zmud/nexus #wait → mudlet

Post Reply
User avatar
Vadi
Posts: 4609
Joined: Sat Mar 14, 2009 3:13 pm

zmud/nexus #wait → mudlet

Post by Vadi » Tue Jul 07, 2009 12:25 pm

Some clients offer a #wait function, which will "pause" the script for a certain amount of time before allowing it to continue.

Mudlet doesn't provide that; it uses timers instead. Timers are better because they are easier to work with (they can be named/enabled/disabled), are less prone to buggy implementations (zmuds, for example, isn't great) and are more flexible.

Timers work a bit differently - instead of freezing the script for a certain amount of time, they don't freeze anything, but run a command in a certain time in the future.

So for example, a pseudocode #wait script:

Code: Select all

do something
#wait 1000
do something2
with a timer, becomes

Code: Select all

do something
set a timer for 1 second to "do something2"
Would be the basic one-to-one translation. But since timers don't freeze the script, you can create several different ones, you can disable and enable them back - which will be a very helpful thing in the future and less code for you to write.

The syntax for using a timer is like this:

[quote]tempTimer (time to wait in seconds, [

Code: Select all

], and optionally a name)[/quote]

So a nexus code of:

[code]#send jerk fish
#wait 1500
#send pull line
Would be the following in Mudlet:

Code: Select all

send ("jerk fish")
tempTimer (1.5, [[send ("pull line")]])
Since timers are created instantly, if you want two or more, or means the times for consecutive timers should be to the starting point, unlike relatives times you do with waits:

Code: Select all

#send jerk fish
#wait 1500
#send pull line
#wait 500
send jump

Code: Select all

send ("jerk fish")
tempTimer (1.5, [[send ("pull line")]])
tempTimer (2, [[send ("jump")]])
Hope that helped! Post comments/questions below.

Caled
Posts: 394
Joined: Thu Apr 09, 2009 4:45 am

Re: zmud/cmud/nexus #wait → mudlet

Post by Caled » Wed Jul 08, 2009 9:08 am

In CMUD the #wait command is one of several ways to tell a script to run in a separate thread, so it is not entirely accurate to include CMUD in that explanation. I just want to mention that in case there is anyone around that knows cmud but does not know zmud.

Lucky24
Posts: 49
Joined: Sun Sep 12, 2010 1:50 am

Re: zmud/nexus #wait → mudlet

Post by Lucky24 » Sun Sep 12, 2010 3:30 am

Do timers affect each other? AKA If two timers are set, will the first command be sent first, and then the second timer added on top?

Also, the Batch Job Timers section on the Mudlet manual is a bit short...

I'm thinking that if I implement timers extensively, I would probably want to make my own send() function, one that has a command buffer of text lines, so that commands are sent with the proper spaces between them, and in the right order.

For example, I see potential problems with the following situation:

The two following triggers can happen consecutively, but not at a predictable interval:

You are very thirsty.
You are hungry.

so we'd set two timers:

tempTimer(2, [[drink water]])
tempTimer(4, [[eat buscuit]])

And setting them to different times as to hope to avoid them being sent at the same time. However, if "You are hungry." happens to occur 2 seconds before "You are very thirsty.", then both commands will be sent at the same time, right?

I ask this because I'm coming from Portal, which has a built-in command buffer and sequential ;wait timers, which I believe is different than clients like zMUD where the ;wait timers are independent to each trigger.

User avatar
Vadi
Posts: 4609
Joined: Sat Mar 14, 2009 3:13 pm

Re: zmud/nexus #wait → mudlet

Post by Vadi » Sun Sep 12, 2010 3:56 am

That sounds like a bad way to do system design.

Looks like what you want is a) a queue of actions you want to do, and b) a timer that allows the next action in the queue to go.

For example, something like...
Code: [show] | [select all] lua
send(<action1>)
block_queue = true
tempTimer(2, [[block_queue = false; check_my_queue();]])

Lucky24
Posts: 49
Joined: Sun Sep 12, 2010 1:50 am

Re: zmud/nexus #wait → mudlet

Post by Lucky24 » Sun Sep 12, 2010 6:50 am

Ok, so a function of this type is neccessary to delay commands. I think I worded the example poorly; it was supposed to be an example of why the timer functions wouldn't work in some situations. Thanks :)

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: zmud/nexus #wait → mudlet

Post by Iocun » Sun Sep 12, 2010 9:06 am

I've posted my own implementation of creating things like #wait queues here.

To go back to the example Vadi posted:
Vadi wrote:

Code: Select all

#send jerk fish
#wait 1500
#send pull line
#wait 500
send jump

Code: Select all

send ("jerk fish")
tempTimer (1.5, [[send ("pull line")]])
tempTimer (2, [[send ("jump")]])
With my sendQueue() function, I'd do the same like this:

sendQueue({"jerk fish", 1.5, "pull line", 0.5, "jump"})

This method makes it possible again to use relative timeouts respective to the last action, similar to using #wait, while still working internally with tempTimers.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest