Scripting a pause in triggers?
Moderator: Eowul
Forum rules
- Use common sense and be respectful towards each other at all times, even when disagreeing.
- Do not reveal sensitive game information. Guild secrets, player seconds are examples of things not allowed.
- Use common sense and be respectful towards each other at all times, even when disagreeing.
- Do not reveal sensitive game information. Guild secrets, player seconds are examples of things not allowed.
Scripting a pause in triggers?
I have made many aliases and triggers. Some of these get to be very long without a pause (traveling to distant lands), adding a pause would allow my computer some time to think between requests.
I know a little of the JS and have an adapted wait function from a previous forum page (that is long and tiresome to copy). Is there a simple wait function that I am to blind to see? Thanks for your help!
I know a little of the JS and have an adapted wait function from a previous forum page (that is long and tiresome to copy). Is there a simple wait function that I am to blind to see? Thanks for your help!
Signed
Kolvar
"Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life." Terry Pratchett >:)
Kolvar
"Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life." Terry Pratchett >:)
Re: Scripting a pause in triggers?
Use do-paths.
"do n, n, n, n, n, w, w, knock on gate, w, n, nw, climb tree, ne, n"
"do n, n, n, n, n, w, w, knock on gate, w, n, nw, climb tree, ne, n"
Nil Mortifi Sine Lucre
Re: Scripting a pause in triggers?
If you want to add a single pause: https://www.w3schools.com/jsref/met_win_settimeout.asp
If you want to add pause between each step: https://www.w3schools.com/jsref/met_win_setinterval.asp
So, for a path to execute with 1 second delays you could simply put it into an array and then iterate over it with setInterval().
Example:
If you want to add pause between each step: https://www.w3schools.com/jsref/met_win_setinterval.asp
So, for a path to execute with 1 second delays you could simply put it into an array and then iterate over it with setInterval().
Example:
Code: Select all
let i = 0;
const ary = ["ne", "ne", "e", "e", "se", "nw", "ne", "ne", "se"];
var myIter;
function iter() {
console.log(ary[i]);
i += 1;
}
function startIter() {
i = 0;
myIter = setInterval(iter, 1000);
}
function stopIter() {
clearInterval(myIter);
}
Time is precious. Waste it wisely.
Re: Scripting a pause in triggers?
Thank you for the links to the webpages! it helped a lot!
Signed
Kolvar
"Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life." Terry Pratchett >:)
Kolvar
"Build a man a fire, he'll be warm for a day.
Set a man on fire, he'll be warm for the rest of his life." Terry Pratchett >:)
-
- Beginner
- Posts: 15
- Joined: 06 May 2019 03:42
Re: Scripting a pause in triggers?
That's great! Thanks, Zhar!
But... Isn't clearInterval()buggy in the webclient? I use it in another alias, but it doesn't seem to actually clear the flag.
But... Isn't clearInterval()buggy in the webclient? I use it in another alias, but it doesn't seem to actually clear the flag.
Re: Scripting a pause in triggers?
This seems a bit convoluted, try:Zhar wrote: ↑08 Jan 2021 11:17If you want to add a single pause: https://www.w3schools.com/jsref/met_win_settimeout.asp
If you want to add pause between each step: https://www.w3schools.com/jsref/met_win_setinterval.asp
So, for a path to execute with 1 second delays you could simply put it into an array and then iterate over it with setInterval().
Example:
Code: Select all
let i = 0; const ary = ["ne", "ne", "e", "e", "se", "nw", "ne", "ne", "se"]; var myIter; function iter() { console.log(ary[i]); i += 1; } function startIter() { i = 0; myIter = setInterval(iter, 1000); } function stopIter() { clearInterval(myIter); }
Code: Select all
/* jshint ignore:start */
const path = ["ne", "ne", "e", "e", "se", "nw", "ne", "ne", "se"];
for (const cmd of path) {
mud.connection.send(cmd)
await wait(0.5)
}
Re: Scripting a pause in triggers?
Sorry, JS is not really my forte.
Callimachus, to be able to clear an interval you need to assign it to a variable first. But what Cotillion posted is indeed much more clear in its intent.
Callimachus, to be able to clear an interval you need to assign it to a variable first. But what Cotillion posted is indeed much more clear in its intent.
Time is precious. Waste it wisely.
http://tworzymyatmosfere.pl/przescieradla-jedwabne-z-gumka/