Scripting a pause in triggers?

General discussion about the Genesis Web Client located at https://www.genesismud.org/play/

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.
Post Reply
Arsonist
Beginner
Posts: 23
Joined: 06 Feb 2019 18:28

Scripting a pause in triggers?

Post by Arsonist » 08 Jan 2021 05:13

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!
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 >:)

User avatar
nils
Titan
Posts: 458
Joined: 22 Jul 2016 17:13

Re: Scripting a pause in triggers?

Post by nils » 08 Jan 2021 10:53

Use do-paths.

"do n, n, n, n, n, w, w, knock on gate, w, n, nw, climb tree, ne, n"
Nil Mortifi Sine Lucre

User avatar
Zhar
Wizard
Posts: 1079
Joined: 17 Apr 2012 12:09

Re: Scripting a pause in triggers?

Post by Zhar » 08 Jan 2021 11:17

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:

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.

Arsonist
Beginner
Posts: 23
Joined: 06 Feb 2019 18:28

Re: Scripting a pause in triggers?

Post by Arsonist » 08 Jan 2021 14:43

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 >:)

Callimachus
Beginner
Posts: 15
Joined: 06 May 2019 03:42

Re: Scripting a pause in triggers?

Post by Callimachus » 10 Jan 2021 20:51

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.

User avatar
cotillion
Site Admin
Posts: 350
Joined: 04 Mar 2010 01:14

Re: Scripting a pause in triggers?

Post by cotillion » 10 Jan 2021 22:39

Zhar wrote:
08 Jan 2021 11:17
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:

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);
}
This seems a bit convoluted, try:

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)   
}

User avatar
Zhar
Wizard
Posts: 1079
Joined: 17 Apr 2012 12:09

Re: Scripting a pause in triggers?

Post by Zhar » 10 Jan 2021 23:41

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.
Time is precious. Waste it wisely.

Post Reply
http://tworzymyatmosfere.pl/przescieradla-jedwabne-z-gumka/