timmaugh said: And... just so I understand... is this the order of things (without regard to concurrency, just the order of how tasks are managed in scripts): A player runs the ScriptCards macro ScriptCards builds a menu of buttons That player clicks a button from the menu, which runs the ChatSetAttr call ? Because in that case I wonder when ScriptCards is stripping off the deferral character. In fact, if Valerio has ZeroFrame installed, s/he could drop a {&log} in the original ScriptCard. The "Loop 1" entry should show how command line was rendered after Roll20 parsing. We could see if the @{select|character_id} is resolving correctly. Also, you could drop a deferred log command in the ChatSetAttr line: {^&log} So that we get a separate log for what THAT script will see. Yes, that's correct ! That's the order of things. This is the simplest "repeating" macro that shows this issue. I'll post this one so we can focus on the actual problem. The other macros are a bit longer and deal with items, abilities, etc...but they all show the same issue (Pathfinder 1 Community Sheet) !script {{ --#sourceToken|@{selected|token_id} --#reentrant|@{selected|token_id} --#title|[*S:character_name] --#oddRowBackground|#000000 --#evenRowBackground|#17202a --#oddRowFontColor|#FFFFFF --#evenRowFontColor|#FFFFFF --#titleCardBackground|#000000 --#leftsub|Potenziamenti --#rightsub|Modifica --#buttonFontSize|11px --#buttonBackground|#000000 --#bodyFontFace|Sans --#whisper|self --Rfirst|[*S:character_id];repeating_buff2 --=n|0 --:Loop| --?"[*R:name]" -eq NoRepeatingAttributeLoaded|Done --=Value|[*R:enable_toggle] --+[rbutton][*R:name]::MOD_BUFF;[$n.Raw][/rbutton]|[r][$Value][/r] --=n|[$n] + 1 --Rnext| -->Loop| --:Done| --X| --:MOD_BUFF| --#whisper| --=R|[&reentryval] --Rfirst|[*S:character_id];repeating_buff2 --=n1|0 --:Loop1| --?"[*R:name]" -eq NoRepeatingAttributeLoaded|Done1 --?[$n1] -eq [$R]|Done1 --=n1|[$n1] + 1 --Rnext| -->Loop1| --:Done1| --=Mod|1 - [*R:enable_toggle] --@setattr|_charid [*S:character_id] _silent _repeating_buff2_$[&reentryval]_enable_toggle|[$Mod] {^& select @{selected|token_id} } {^&log} --?[$Mod] -eq 0|DISABLED --+[*R:name]|Enabled --^End| --:DISABLED| --+[*R:name]|Disabled --:End| --X| }} As you can see, it creates a button for each buff in the sheet and allows you to toggle that buff. A note about the second loop in the reentrant part, I have to "find the buff again" as I can't really use anything like @{selected|repeating_buff2_$[$anyvariablehere]_enable_toggle}, as I asked in this same thread a while ago. But I think that's beyond the point. This works correctly when no concurrency between players occurs. timmaugh said: Also, can you confirm that the second user only has to click on their token to make this work? The API doesn't know that you clicked on a token until you run a script command. Just because someone clicked on a token shouldn't change anything about an API message's set of selected tokens. There is no interaction with the API (or changing a state that the API cares about) without running an API command. So is Player B doing more than selecting their token? Yes. The only thing is that Player B could have used the same macro (with no issues) before Player A. That's why I mentioned the fact that the API gets buggy after a "couple of times that this sequence happens" David M. said: What about this: Can you just have the original scriptcard (the one that creates the buttons) hardcode the character_id into each button when they are created (using a string variable like [&charID]), rather than the button content relying on @{selected...}? Hi David, thank you for your answer. I've read your code, it's actually a brilliant solution, and it might work I'm gonna try this one too! timmaugh said: Because in that case I wonder when ScriptCards is stripping off the deferral character. In fact, if Valerio has ZeroFrame installed, s/he could drop a {&log}
in the original ScriptCard. The "Loop 1" entry should show how command
line was rendered after Roll20 parsing. We could see if the
@{select|character_id} is resolving correctly. Also, you could drop a
deferred log command in the ChatSetAttr line: {^&log} So that we get a separate log for what THAT script will see. Valerio can you do that and post your logged results for both (they will appear in chat)? I've installed ZeroFrame as you suggested and this is the result for the macro I've posted, (toggling the first buff) I'm going to try David's and Kurt's solutions and I'll report here the results! Thank you all guys, you're awesome!