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
➜ Programming
➜ General
➜ Recursive timer not firing
|
Recursive timer not firing
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Areadien
USA (47 posts) Bio
|
| Date
| Fri 16 Mar 2018 01:41 AM (UTC) |
| Message
| So I have Lua this function here, where, when I type the alias "test timer", "5\n", "4\n", "3\n", "2\n", "\1", is displayed, with each line being displayed 0.1 after the previous one, then display "done" when count is 0. Problem is, even though count is being decremented, the timer isn't working, and I don't know why. Any other similar timers I have are working fine. At first, I thought maybe that the timer called the function it's in was why it's not working, but I just tested that hypothesis by calling "testTimer2()" to call "testTimer()", but it's still now working. I even made the test_timer not be OneShot, but that didn't work either. What am I doing wrong?
local count = 5
function testTimer()
ColourNote("blue", "black", count)
count = count - 1
if count == 0 then
ColourNote("cyan", "black", "done")
else
AddTimer("test_timer", 0, 0, 0.1, "testTimer()", timer_flag.Enabled + timer_flag.OneShot)
SetTimerOption("test_timer", "send_to", 12)
end
end
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Fri 16 Mar 2018 03:27 AM (UTC) Amended on Fri 16 Mar 2018 06:17 AM (UTC) by Nick Gammon
|
| Message
| Can you show the alias?
 |
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
|
Possibly the issue is that you are adding the timer test_timer when such a timer already exists. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Areadien
USA (47 posts) Bio
|
| Date
| Reply #2 on Sun 18 Mar 2018 06:11 PM (UTC) Amended on Sun 18 Mar 2018 06:12 PM (UTC) by Areadien
|
| Message
| Yeah, it's
<alias enabled="y" match="^testTimer$" regexp="y" send_to="12" sequence="100">
<send>testTimer()</send>
</alias>
| | Top |
|
| Posted by
| Areadien
USA (47 posts) Bio
|
| Date
| Reply #3 on Sun 18 Mar 2018 10:35 PM (UTC) Amended on Sun 18 Mar 2018 10:38 PM (UTC) by Areadien
|
| Message
| OK, I figured out what was going on, but that raises two new questions. The timer wasn't working because I didn't have a connection to the game server. Is there any way I can make the timer work while I'm offline?
Also, setting timer_flag.OneShot doesn't make the timer fire until count == 0; it just displays 5 and then 4, and then it stops. But not setting timer_flag.OneShort makes the timer go ad infinitum. How can I fix this problem? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Sun 18 Mar 2018 11:41 PM (UTC) |
| Message
| If you add the "check" function call you can debug a bit better, like this:
if count == 0 then
ColourNote("cyan", "black", "done")
else
check (AddTimer("test_timer", 0, 0, 0.1, "testTimer()", timer_flag.Enabled + timer_flag.OneShot))
SetTimerOption("test_timer", "send_to", 12)
end
When I did that I saw, after two ticks:
Run-time error
World: smaug2
Immediate execution
[string "Script file"]:778: Attempt to add a timer that already exists
stack traceback:
I suggest adding the flag "timer_flag.Replace" to the other two flags you are using.
Also, nothing ever sets the count back to 5, so I suggest removing:
... from the script, and adding it to the alias, eg.
<send>
count = 5
testTimer()
</send>
However your problem then is that if you ever use "count" somewhere else you may throw out this counter.
What might be better would be to make a timer that isn't one shot, and in the timer script check to see how many times it has fired, and when it has fired 4 times set it to one-shot then. That way you don't need an external counter.
GetTimerInfo (10) should tell you how many times the timer fired. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Areadien
USA (47 posts) Bio
|
| Date
| Reply #5 on Wed 21 Mar 2018 10:55 AM (UTC) |
| Message
|
Nick Gammon said:
If you add the "check" function call you can debug a bit better, like this:
if count == 0 then
ColourNote("cyan", "black", "done")
else
check (AddTimer("test_timer", 0, 0, 0.1, "testTimer()", timer_flag.Enabled + timer_flag.OneShot))
SetTimerOption("test_timer", "send_to", 12)
end
When I did that I saw, after two ticks:
Run-time error
World: smaug2
Immediate execution
[string "Script file"]:778: Attempt to add a timer that already exists
stack traceback:
I suggest adding the flag "timer_flag.Replace" to the other two flags you are using.
But I thought OneShot was supposed to delete the timer. Why doesn't it? Also, I tried adding timer_flag.Replace, but it didn't change anything. And I'm not sure how to use the check() function since I tried it and got nothing, not even when I did a ColourNote() with it. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) Bio
Forum Administrator |
| Date
| Reply #6 on Wed 21 Mar 2018 08:44 PM (UTC) |
| Message
| Yes, one-shot deletes the timer. After it has done its stuff. I can't delete something that is running code, so you can't delete the timer while it is running its script.
The check function just tests return codes from the scripting functions (not all of them work with it). However the ones that are documented to return an error code of some sort, and eOK for no error, can have "check" wrapped around them. If there is no error you don't see anything. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
26,187 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top