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
➜ Bug reports
➜ function run by a timer can't create another timer to re-run itself?
function run by a timer can't create another timer to re-run itself?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Fiendish
USA (2,535 posts) Bio
Global Moderator |
Date
| Thu 23 Jun 2016 04:38 PM (UTC) Amended on Thu 23 Jun 2016 04:39 PM (UTC) by Fiendish
|
Message
|
times_fired = 0
function test_timer()
times_fired = times_fired+1
print(times_fired)
AddTimer("mytimer", 0, 0, 0.1, "test_timer()", timer_flag.Enabled + timer_flag.OneShot + timer_flag.Replace + timer_flag.Temporary, "")
SetTimerOption("mytimer", "send_to", sendto.script)
Repaint()
end
test_timer()
This prints
and then it stops. Why? What am I doing wrong here? |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Fiendish
USA (2,535 posts) Bio
Global Moderator |
Date
| Reply #1 on Thu 23 Jun 2016 04:58 PM (UTC) Amended on Thu 23 Jun 2016 05:05 PM (UTC) by Fiendish
|
Message
| Doing this works.
times_fired = 0
function test_timer()
times_fired = times_fired+1
print(times_fired)
AddTimer("mytimer"..times_fired, 0, 0, 0.1, "test_timer()", timer_flag.Enabled + timer_flag.OneShot + timer_flag.Replace + timer_flag.Temporary, "")
SetTimerOption("mytimer"..times_fired, "send_to", sendto.script)
Repaint()
end
test_timer()
But it breaks timer_flag.Replace because they'll never have the same name.
It suggests that OneShot is both trying to remove the timer _after_ my function call instead of before (and isn't removing _that_ timer but any timer with the name) so that it is trapping my newly created timer instead of the one that just expired.
Making OneShot evaluate first before the code is run would probably fix this. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #2 on Thu 23 Jun 2016 08:17 PM (UTC) |
Message
| Yes, but you can't delete a timer (which is what one-shot does) and then evaluate its stuff. And I'm reluctant to remember pointers rather than names, because - during script execution - that pointer might become invalid. Hence it deletes by name.
If you hadn't assigned a name you would get a new automatically-generated name each time and the problem goes away.
But you needed the name to make it send-to-script, right? So how about using addxml? Like this:
require "addxml"
times_fired = 0
function test_timer()
times_fired = times_fired+1
print(times_fired)
addxml.timer { second = 0.1,
send = "test_timer ()",
send_to = sendto.script,
enabled = true,
one_shot = true,
temporary = true,
active_closed = true,
}
Repaint()
end
test_timer()
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Fiendish
USA (2,535 posts) Bio
Global Moderator |
Date
| Reply #3 on Fri 24 Jun 2016 02:35 AM (UTC) Amended on Fri 24 Jun 2016 02:40 AM (UTC) by Fiendish
|
Message
|
Quote: Yes, but you can't delete a timer (which is what one-shot does) and then evaluate its stuff.
What about removing it from the list to search up front but not deleting the actual object until after? Or mangle the name so that a new one doesn't conflict, since at least _my_ expectation was that at the time of the resulting action the named timer no longer exists. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #4 on Fri 24 Jun 2016 03:29 AM (UTC) |
Message
| If I save the object pointer, then run a script, the script might delete the pointer, so it is an error to delete it after the script runs.
Generating a new name, putting it into the timer, and then looking that up afterwards seems an unnecessary overhead to me.
Quote:
... _my_ expectation was that at the time of the resulting action the named timer no longer exists
Why though? You made a timer, you got it to call a script. Surely the timer exists at that point? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Fiendish
USA (2,535 posts) Bio
Global Moderator |
Date
| Reply #5 on Fri 24 Jun 2016 03:57 AM (UTC) Amended on Fri 24 Jun 2016 04:01 AM (UTC) by Fiendish
|
Message
|
Nick Gammon said:
Why though? You made a timer, you got it to call a script. Surely the timer exists at that point?
Just a difference of expectation I guess. At that point, to me, the timer is done because the time has elapsed.
For now I've achieved my basic goal in this case by actually using something close to my "it works this way" example and changing the timer name for subsequent calls, starting at 0 for the main kickoff each time, and ignoring the odd accidental misfire (because the previous invocation doesn't get replaced anymore by new ones) because the work pool is global so there's actually no work left to be done so the time cost of the (at most a handful) misfires is negligible.
Now I need to find a fix for my WindowAddHotspots taking so long. |
https://github.com/fiendish/aardwolfclientpackage | 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.
14,285 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top