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

Delay between macro commands

March 25 (8 years ago)
Is there a working method to delay commands in a multi-command macro?

Previously discussed here:
https://app.roll20.net/forum/post/319863/request-d...

I tried https://wiki.roll20.net/Script:Store_Commands
but that throws errors out of the box, not updated in a year so no longer compatible perhaps.
March 25 (8 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
If you mean with a script, sure, just don't think ones been written for that exact purpose. I've got a similar functionality in Roll20AM.
March 25 (8 years ago)
Well for example I would like a macro like this:

!shaped-apply-defaults
!shaped-expand-spells

To be this:

!shaped-apply-defaults
<500ms pause>
!shaped-expand-spells
Probably wont help, but i have been trying this for the shape shifting i want for the Druid, and i have had to write my own API script for it.
March 25 (8 years ago)

Edited March 25 (8 years ago)
Thorsten
KS Backer
The way the chat is parsed, I don't think this is trivial.

I tried this as a macro:

Starting
!wait 500
Ending

And the output is:

10:51AMThorsten (GM): Starting
Ending
10:51AM(From WAIT): 500 ms

Which means macros don't wait for something to complete before going on to the next command to output into chat.
That "From WAIT" line is a debug message in the !wait API I cobbled together.

Edit: Okay, so what if "wait" could take a command, and then execute that after the wait. That might work.
Or take multiple commands and execute them with a wait in between each.
Which do you think would work best, here? What are your use cases?
Is it preferable to specify a custom wait between each command, or should it be just a standard wait, and then execute commands in order with the specified wait in between?

I can probably steal some code from GroupCheck to make this work.

For reference, this is a wait script that does nothing but wait:
// VERSION INFO
var Wait_Author = "Thorsten";
var Wait_Version = "1.0";
var Wait_LastUpdated = 1490451480;


// FUNCTION DECLARATION
var WaitScript = WaitScript || {};


on("chat:message", function (msg) {
	if (msg.type != "api") return;
	if (msg.content.split(" ", 1)[0] === "!wait") {
		msg.who = msg.who.replace(" (GM)", "").split(" ", 1)[0];
		msg.content = msg.content.replace(/<br\/>\n/g, ' ').replace(/({{(.*?)}})/g, " $2 ");
		var n = msg.content.split(" ", 2)[1];
		if (!WaitScript.isPositiveInteger(n)) {
		    sendChat("WAIT", "/w " + msg.who + " You did not give a wait time (in ms).");
		    return;
		}
		if (n > 500) {
		    sendChat("WAIT", "/w " + msg.who + " Waiting for more than 500ms is not supported, as it may crash the API sandbox.");
		    return;
		}
		WaitScript.Wait(n);
		sendChat("WAIT", "/w " + msg.who + " " + n + " ms");
	}
});


on("ready", function () {
	log("-=> Wait v" + Wait_Version + " <=-  [" + (new Date(Wait_LastUpdated * 1000)) + "]");
	//log (Date.now().toString().substr(0, 10));
});


WaitScript.Wait = function (ms) {
    var d = new Date();
    var d2 = null;
    do { d2 = new Date(); }
    while(d2-d < ms);
}


WaitScript.isPositiveInteger = function (n) {
    return n >>> 0 === parseFloat(n);
}

March 25 (8 years ago)

Arno said:

Well for example I would like a macro like this:

!shaped-apply-defaults
!shaped-expand-spells

To be this:

!shaped-apply-defaults
<500ms pause>
!shaped-expand-spells

You'd have to ask Lucian to expand the script to allow you to use those two functionalities within one command.
March 25 (8 years ago)
The best way to stagger execution of API commands in a specific order would be to number them and then execute them in that order with the specific delay between them.

!delay 1 500 token-mod ...
!delay 2 2500 token-mod ...
!delay 3 5000 token-mod ...
March 25 (8 years ago)
Thorsten
KS Backer
@SkyCaptain I don't understand the API well enough to implement something like that. Wouldn't this call !delay three times, each unaware of the other calls?

Over to someone better versed in JS in general and the roll20 API in particular :).
March 25 (8 years ago)
Lithl
Pro
Sheet Author
API Scripter

Thorsten B. said:

@SkyCaptain I don't understand the API well enough to implement something like that. Wouldn't this call !delay three times, each unaware of the other calls?
Yes, but the first one would wait 0.5s before doing something, the second would wait 2.5s, and the third one would wait 5s.

Arno said:
I tried https://wiki.roll20.net/Script:Store_Commands
but that throws errors out of the box, not updated in a year so no longer compatible perhaps.
I'm the author. I haven't touched it because few people have used it (so adding features isn't a priority) and I haven't gotten bug reports. What's the error you got?