Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

I think my API scripts are firing multiple times from the same event/command. What is happening here?

I have a few API scripts I use for my games that really improve the experience. In this particular game, I'm a player and someone else is the DM. I have been granted DM privileges in this game so I can do the API stuff and macro work for him. Last night, during our game, someone noted that our Temporary HP script stopped working. That script activates whenever someone takes damage. It checks to see if the character has temp hp. If they do, then it will apply the damage to that first and then restore that amount to their health bar (effectively dealing damage to the temp hp rather than the hp). While I was debugging that, I noticed that the event that triggers on the line below was firing anywhere from 10-12 times per update to the HP bar. on("change:token", accountForHPBarChange); Notably, updating hp through token mod seemed to work just fine. But if you click the red circle and type in "-1" to take 1 point of damage, the script would run recursively until the temp hp was 0 and that 1 point of damage was applied to the token's health. Strange. While messing around with the api stuff I noticed another strange happening. !token-mod {{     --set          bar3_value|+[[?{How many dice will you spend to heal your ally?|1|2|3|4|5}d6]]     --ids          -MYqebhy9B5EzG7Tocil     --report         all|"/em Rue channels the light of the heavens himself to bestow a blessing to {name}, healing for {bar3_value:abschange}."         gm:control|"Rue spent ?{How many dice will you spend to heal your ally?|1|2|3|4|5} charges of healing light to heal Sun'Chu'Luk for {bar3_value:abschange}. Rue has @{Rue|class_resource} charges left of Healing Light. They recharge on a long rest." }} /fx beam-holy @{selected|token_id} -MYqebhy9B5EzG7Tocil -MYqebhy9B5EzG7Tocil !setattr --name Rue --modb --silent --class_resource|-?{How many dice will you spend to heal your ally?|1|2|3|4|5} !roll20AM --audio,play|Better Healing Light In this token action, our Celestial Warlock, Rue, would use his Healing Light subclass feature to heal a target with some d6 dice. In the actual token action, he has a button for each party member and a "Target" button, so he could feasibly target an NPC or something. (I like to avoid having uneccessary clicks, as the @{target|Target|token_id} often feels).  Whenever I run that macro I get the output attached at the bottom. Okay, for some reason token mod took the 1 command and ran it twice. The second time it didn't actually do anything. It shows 0 healing. But still, strange. It ran twice. What could cause an api to run multiple times like this? I have confirmed that I only have 1 instance of Token-Mod installed. Same for TempHP.
1620326833

Edited 1620328386
timmaugh
Forum Champion
API Scripter
There is a known bug (stemming from about the time of the upgrade to take Roll20 from one shard to many) where the former sandbox doesn't always shut down. Really, it's two bugs happening together: the former sandbox, upon encountering an error, attempts to stabilize itself and re-ish boots. It doesn't quite make it. It's like the person in the movies who has been shot but assures everyone around them they'll be OK. Just let 'em sit there. Rest a bit. Maybe die for a while. But they're fine. Right as rain. So, that sandbox is still running. Then, the second bug... When you perform a sandbox reboot, the old sandbox *still* doesn't shut down immediately (you didn't know you were signing up for the Apocalypse Roach of sandboxes, did you? No one expects the Apocalypse Roach!) That means there is sometimes a window after a sandbox reboot where you have multiple sandboxes running, each one trying to answer the script handle. You can see it sometimes... for instance, if your script has a particular log message, and you change that log statement, then reboot your sandbox and immediately trigger the script. You'll get 2 different log statements (1 of the former variety, 1 of the new). Probably happening on that recursion too (maybe?)... one sandbox triggers a change in the other... triggering a change in the former... back and forth until they burn themselves down.