Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ question about wait.lua-Why the addtimer's sending script has no argument
question about wait.lua-Why the addtimer's sending script has no argument
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Wayen
China (17 posts) Bio
|
Date
| Fri 14 Oct 2016 04:09 PM (UTC) Amended on Fri 14 Oct 2016 10:04 PM (UTC) by Nick Gammon
|
Message
| I researched this code and find a question that is the addtimer's sending script-wait.timer_resume has no argument,but the function definition has argument like this:
function timer_resume (name)
if the timer trigger the script(wait.timer_resume),How could the function(timer_resume) recongnize the argument and find the thread which stored in table(threads)?
-------------------------------------------------------------
function timer_resume (name)
local thread = threads [name]
if thread then
threads [name] = nil
local ok, err = coroutine.resume (thread)
if not ok then
ColourNote ("deeppink", "black", "Error raised in timer function (in wait module).")
ColourNote ("darkorange", "black", debug.traceback (thread))
error (err)
end -- if
end -- if
end -- function timer_resume
function time (seconds)
local id = "wait_timer_" .. GetUniqueNumber ()
threads [id] = assert (coroutine.running (), "Must be in coroutine")
local hours, minutes, seconds = convert_seconds (seconds)
check (AddTimer (id, hours, minutes, seconds, "",
bit.bor (timer_flag.Enabled,
timer_flag.OneShot,
timer_flag.Temporary,
timer_flag.ActiveWhenClosed,
timer_flag.Replace),
"wait.timer_resume"))
return coroutine.yield ()
end -- function time
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Fri 14 Oct 2016 10:08 PM (UTC) |
Message
| The argument to AddTimer is "wait.timer_resume".
That is a string, not a function call. It tells the timer code what function to call when the timer fires. Built into the code that calls that function is the knowledge that it adds the timer name (which is stored in the timers table).
Similarly, in a trigger, you can supply the name of a function to call when the trigger fires. The code that does that adds four arguments: name, line, wildcards, styles |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Wayen
China (17 posts) Bio
|
Date
| Reply #2 on Sat 15 Oct 2016 11:02 AM (UTC) |
Message
| Ok,I see now.The AddTimer call function(wait.timer_resume) that will add argument(Timer'id) to the function. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
11,028 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top