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

[Request] Delay command...

I'm trying to set up a macro that uses multiple api commands, but they're not executing in order or displaying in the chat in order. Is there a way we could get some kind of macro or api command that does a short 50ms delay or something to prevent this out of order display?
1378103133

Edited 1378103297
Lithl
Pro
Sheet Author
API Scripter
I think this script will do what you're asking for (and possibly more). Commands: !delay time - Set a default time delay between each command when the store is run. Time is in milliseconds, so 1000 is 1s. !store [! time ] command - Store a command to be executed later. Time can be optionally added to the beginning (prepend with an exclamation mark), which sets the delay for this command only. Command can be anything you could enter in chat, plus the /direct command. !clearstore - Clears the command store !echostore - Sends you whispers to tell you what commands are in your store, and what their delays are !run - Runs the stored commands in the order they were stored, with the given delay between each command. If the first command has a delay, the script will wait that long before executing it. When the commands are run, it will be you (the player) saying anything in chat. Each player has their own store they can build up and run. Unless you set a delay (using either !delay or the optional parameter of !store), the script will use a 500ms delay. <a href="https://gist.github.com/Lithl/6409724" rel="nofollow">https://gist.github.com/Lithl/6409724</a>
1378111324

Edited 1378111665
Alex L.
Pro
Sheet Author
Just FYI if you are having problems where API commands are executed before normal commands but respond after then this is something I have already pointed out and the correct way to fix it would be to have a blocking chat event in the API (with an appropriate timeout), also an API delay command will do nothing to fix this. If you are having problems with API commands executing in the wrong order then you will need to post the code as that shouldn't be possible. Some times this problem can be caused by poorly optimized code so it would be worth a look, but sometimes the operation being performed just takes to long no mater what.
1378120253

Edited 1378120473
!attack Chimera Bite 7 3d6+4 piercing&nbsp;?{Advantage|No} ?{Disadvantage|No} !attack Chimera Gore 7 1d12+4 piercing&nbsp;?{Advantage|No} ?{Disadvantage|No} !attack Chimera Rake 7 2d6+4 slashing&nbsp;?{Advantage|No} ?{Disadvantage|No} &nbsp; &nbsp; if (msg.type == "api" &amp;&amp; command == "!attack") { &nbsp; &nbsp; &nbsp; &nbsp; msg.content = msg.content.replace("!attack ", ""); &nbsp; &nbsp; &nbsp; &nbsp; msg.content = msg.content.trim(); &nbsp; &nbsp; &nbsp; &nbsp; if (n.length &lt; 5) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("ERROR", "/w " + msg.who + " You must include the name of the attacker, the attack name, the attack bonus, the damage roll, and the damage type."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Define variables &nbsp; &nbsp; &nbsp; &nbsp; var Attacker = n[1]; &nbsp; &nbsp; &nbsp; &nbsp; var AttackName = n[2] &nbsp; &nbsp; &nbsp; &nbsp; var AttackBonus = n[3]; &nbsp; &nbsp; &nbsp; &nbsp; var DamageRoll = n[4]; &nbsp; &nbsp; &nbsp; &nbsp; var DamageType = n[5]; &nbsp; &nbsp; &nbsp; &nbsp; var Advantage = n[6].toLowerCase(); &nbsp; &nbsp; &nbsp; &nbsp; var Disadvantage = n[7].toLowerCase(); &nbsp; &nbsp; &nbsp; &nbsp; if (Advantage == "yes") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var AttackRoll = "{2d20KH1}"; &nbsp; &nbsp; &nbsp; &nbsp; } else if ( Disadvantage == "yes") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var AttackRoll = "{2d20KL1}"; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var AttackRoll = "1d20"; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "/emas " + Attacker + " makes an attack!"); &nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "&lt;b&gt;Attack:&lt;/b&gt; " + AttackName); &nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "[[" + AttackRoll + "+" + AttackBonus + "]] to hit"); &nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "[[" + DamageRoll + "]] " + DamageType + " damage"); &nbsp; &nbsp; }
1378123117
Lithl
Pro
Sheet Author
API Scripter
I've noticed a similar problem with my roll repeater script. In my case, the output is usually in the correct order, but sometimes the order will change, even just mashing the same macro over and over. I suspect the API calls and/or the sendChat function are being processed asynchronously, so there are simply no guarantees about the order. Also, I realized in the script I posted, it'll eat the ! from any API command you try to store, thinking you're setting a delay on the stored command. I changed the '!' on line 21 to '-'
1378123944
Alex L.
Pro
Sheet Author
I didn't think the chat was asynchronous but its possible that is could be. The best way to get round this would be a producer/consumer queue. basically you have a function that runs and adds the command to a array then triggers a function that starts looping through the array progressing each command in order. you would have to put protection in to make sure it only processess one thing at a time and maybe exicute the proccessing function on a timer as a backup, but it would solve the problem.