tempTimer is going off immediately

Share your scripts and packages with other Mudlet users.
Post Reply
Katerine459
Posts: 6
Joined: Mon Nov 26, 2018 9:59 pm

tempTimer is going off immediately

Post by Katerine459 »

Hi,
I have what I hope is a simple question. I have an alias, where I want to send the "sc" command (to get the "score" screen), then wait for the score screen to appear (because there's a separate trigger to get the number of coins I have in hand), then run another command. Here's the alias code (called depc):

Code: Select all

local function DepositCoins()
  local CoinsToDeposit = CoinsInHand - math.fmod(CoinsInHand,5000)
  send("deposit " .. CoinsToDeposit)
end

send("sc")

tempTimer(20,DepositCoins())
But even when the tempTimer is set to a ridiculous number of seconds (like the 20, above), there is no wait. The "sc" command gets sent, then "deposit x" (where x is the number of coins) is sent immediately after that, and then the "sc" command comes through.

So... here's what I know. It's not that the code doesn't work at all... it does. It's not that the code is running out of order... it isn't ("sc" is sent first, then deposit x"). It's that the tempTimer does not appear to be, well, doing a temp timer.

Using Mudlet 3.15.0.

Thanks!

User avatar
Zaphob
Posts: 180
Joined: Wed May 09, 2012 8:07 am
Location: mg.mud.de

Re: tempTimer is going off immediately

Post by Zaphob »

Hi Katerine459!

The tempTimer will indeed wait for you, however the syntax needs to be a bit different. The way you wrote it, your function will be executed immediately when defining the Trigger. The result of your function will then be used as argument for said trigger when the time is done. That will probably not help or be what you want. Instead you have two options:

1) Wrap your function name as a string with "" or [[]] like so:

Code: Select all

tempTimer(20,[[DepositCoins()]])
This is the old way and works fine. However it will break syntax highlighting and can become a bit ugly when longer functions are involved.

2) Since some recent Mudlet version, you can also use anonymous functions in this place:

Code: Select all

tempTimer(20,function() DepositCoins() end)

See more information in wiki: https://wiki.mudlet.org/w/Manual:Introduction#Timers


Let us know if this helps or you need any other support :)

Katerine459
Posts: 6
Joined: Mon Nov 26, 2018 9:59 pm

Re: tempTimer is going off immediately

Post by Katerine459 »

Thanks! That did the trick. :)

Post Reply