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

Calling several scripts from a macro but only the first is executed

Hello,  I'm trying to call 2 scripts and only the first one is called (and perfectly executed). I pretty sure it is a problem inside my scripts it works if I am calling nearly empty script. But I am not able to figure the root cause inside my scripts. I am guessing it is a javascript issue like if I am interrupted the pipeline execution or maybe overcharged some instruction ? Fun fact sometime if I click several times on the macro buton sometime (very few to be honnest) the 2 scripts are executed. Macro used : !spellbook -resetSpellUsed 1 @{selected|token_id} !ki -reset @{selected|token_id} 0 or !spellbook -resetSpellUsed 1 @{selected|token_id} !spellbook -resetSpellUsed 2 @{selected|token_id} Script used : DWspellbook.js DWki.js PS : let me know if you want I add you in my game in order to test
1644671204

Edited 1644671389
David M.
Pro
API Scripter
This is a known issue. I don't remember ever seeing a solution for it, though. EDIT - FYI: putting [SCRIPT] at the front of a forum post typically indicates that you are sharing a new script in the post. 
1644677201

Edited 1644677270
The workaround is to make one of them a macro thats called beside the other so that the double api calls bug doesn't happen I believe.  Makes you have to overpopulate the collections tab but its the only thing I've seen to solve it.   You could also make the macro an npctraits template with 2 api chat buttons for both abilities and have the player manually fire them.  
Sorry David, is there anyway to edit the post title to remove the script tag ? Eddie I currently use the 2 api chat buttons but one of my player often forget to click on both so I'm wondering if there is someway to smooth thing :) So I gess I have to create a dependency between the scripts and call the function internally, thanks
1644680250
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
David M. said: Sorry David, is there anyway to edit the post title to remove the script tag ? Hi David, The best way is to click the "Report" button in our original post (you won't get in trouble) and explain your need to a moderator. Chances are on the next sweep, they can change your title for you.
1644680714
David M.
Pro
API Scripter
Regarding the thread title - it's nbd, just something to keep in mind for the future.
David M. said: Sorry David, is there anyway to edit the post title to remove the script tag ? Eddie I currently use the 2 api chat buttons but one of my player often forget to click on both so I'm wondering if there is someway to smooth thing :) So I gess I have to create a dependency between the scripts and call the function internally, thanks Omg I have a genius idea but....it requires you to somehow make the apichat button fail to prevent expansion.  If you go to the APIchat wiki there are characters in apichat buttons you have to escape so that the command does not auto resolve when its within a template or macro call.  So if you can somehow make the api chat button use one of those characters then when you fire a generic template..it will auto expand both buttons as if they'd been pressed with the first command.  Its actually a bug I personally hate but for you it would work around the bug you are fighting.  Your commands don't seem to have any of the characters but if you turned them into macro calls the macro has escapes to not expand as you have to escape the page return character.  
1644686722
The Aaron
Roll20 Production Team
API Scripter
David M. said: PS : let me know if you want I add you in my game in order to test Hey David, if you want to PM me an invite and GM me, I'll take a look and see if I can figure anything out.
Thanks Aaron, invitation sent Eddie, I'm little reluctant to exploit a bug but it's an interesting idea, i will let you know when I try it :)
1644861212
timmaugh
Forum Champion
API Scripter
Yeah, I filed a Bug Report about this last year. I think somewhere around June of last year there was a big update that coincided with the errant behavior. Another solution is that you can embed one call in the other using Plugger: !spellbook -resetSpellUsed 1 @{selected|token_id} {&eval}!ki -reset @{selected|token_id} 0{&/eval} That will effectively turn it into a single line which Roll20 will pick up. Then Plugger will pull out the embedded command and run it first, removing it from the line it is housed in, before releasing *that* message to be caught by the original script. To put it another way, you issue the above command, and... ...Plugger catches the message, detects the embedded bit, and issues a new message: !ki -reset @{selected|token_id} 0 ...Plugger removes the EVAL block from the original message and lets it pass on to the other APIs: !spellbook -resetSpellUsed 1 @{selected|token_id} ...then the spellbook api sees that modified message and takes whatever appropriate action you are instructing. Some things to consider regarding this approach: 1) the embedded command is issued before the housing command finishes, so if there is a required order, you want the one-to-be-executed-first to be in the EVAL block 2) the embedded command is issued in such a way that it might not finish before control returns to the housing command. If it is imperative that the first command resolve before another, you might need to use the Delay script to delay your outer command. This won't stop Plugger from working since it gets a hold of the original message (with the outer and inner API calls) before Delay does. It issues the embedded command, and then hands the remaining message off to Delay... which politely waits for a designated amount of time before firing off the outer command. 3) A few things are different about a message sent from a user versus one sent by a script (API-generated). Since Plugger will be issuing the command line you put in the EVAL block, it will be API-generated. SelectManager is another metascript (like Plugger) that can mitigate this difference.
Thanks Timmaugh it's working