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 .
×
May your rolls be merry + bright! 🎄
Create a free account

settimeout explanations

Hello, can I call this function inside a macro, say to delay the two actions in the macro. What I am writing is : !Macro1 !setTimeout(function() {!Macro2}, 1000) I know there is something totally wrong, can anyone help ? Thanks in advance
1643890334
David M.
Pro
API Scripter
You seem to be mixing javascript syntax (setTimeout) with macro syntax. Any javascript put directly into the the macro editor will not be recognized and spit out an error. Also, the ! at the start of a macro line tells the parser to send a message to the api. So your first line would only be valid if there was an api script that was listening for the string "Macro1". You should instead use # or % (for collections macros or character sheet abilities, respectively), as described here . 
Ok very very humble thanks. So I could (theoritecally) create an api script around the javascript function settimeout, then call that script in a macro. Thanks again
1643892278
David M.
Pro
API Scripter
Yes, but note that an api script can't directly call a macro (so you can't just perform a sendChat() with the text "Macro2" and expect results). You could in theory have the script grab the contents of Macro2 and regurgitate it to the chat with something like this: let thisMacro = findObjs({ type: 'macro', name: 'Macro2' })[0]; sendChat('scriptName', thisMacro.get('action')); However, also note that if there was stuff in Macro2 like @{selected|...} or @{target|...} you'd have to handle it in some way (possibly using one of Tim's metascripts like SelectManager? I dunno). If that applies here, another option might be to avoid the scripting entirely and structure your parent macro to call Macro1 then whisper a chat menu button  that references Macro2. #Macro1 /w gm [buttonText](!
#Macro2)  The time it would take you to fire Macro1 and navigate your mouse cursor to the chat window to click the button would be close to the 1 sec delay you were trying to get with the setTimeout. 
1643900767
The Aaron
Roll20 Production Team
API Scripter
There's code for regurgitating macros in a meaningful fashion in OnMyTurn, if you wanted to dig into it.