463 posts
Location
Germany
Posted 27 June 2012 - 04:02 PM
In my program, there is a timer in a function, and if I restart the function, sometimes comes the Error that the timer event was fired. But: The timer started in the call of the function before, and there is no option to stop this timer and to prevent that the timer event is fired anyway. And I cant wait 10 secs before I start the function again. Then I had an idea to prevent all that: os.startTimer could have a second Variable to the Name (String) Variable. And with os.stopTimer(name) you can delete this Timer. Its would be very useful for me and probably some other coders.
1604 posts
Posted 27 June 2012 - 04:36 PM
I don't think it's needed. Tell us what you'r trying to do, cause there must be a way to do it.
510 posts
Posted 27 June 2012 - 06:59 PM
I think his problem is that you can't remove a timer; it will continue posting events forever.
1604 posts
Posted 27 June 2012 - 07:34 PM
But you can just ignore the event, what's the problem with that?
463 posts
Location
Germany
Posted 27 June 2012 - 08:00 PM
But you can just ignore the event, what's the problem with that?
Because I am waiting for the timer event that I started in the actual function call, and not in the function call before. I can't ignore the event because its needed.
1604 posts
Posted 27 June 2012 - 08:37 PM
But you have to check if the timer you get is the correct one. So, store the timer in a variable, and use it to compare:
local timer
local function startTimer(n)
timer = os.startTimer(n)
end
startTimer(1)
while true do
local evt, arg = os.pullEvent("timer")
if arg == timer then
print("Time's out")
break
end
end
2447 posts
Posted 28 June 2012 - 11:20 AM
I think his problem is that you can't remove a timer; it will continue posting events forever.
Except it only posts an event once.
463 posts
Location
Germany
Posted 28 June 2012 - 02:27 PM
@MysticT: do you really think it works? os.startTimer() returns an empty table and the arg of the event is a number (the time)
Thx works :P/>/>
Edited on 28 June 2012 - 12:51 PM
1604 posts
Posted 28 June 2012 - 06:04 PM
@MysticT: do you really think it works? os.startTimer() returns an empty table and the arg of the event is a number (the time)
Thx works :P/>/>
Yes, the empty table is just a token to idetify the timer, since tables are guaranteed to be unique.