This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
eastar's profile picture

Problem with os.cancelTimer()

Started by eastar, 24 May 2015 - 10:04 PM
eastar #1
Posted 25 May 2015 - 12:04 AM
Hello!

I'm not much of a programmer so I'm a bit lost now. I really have no idea what the problem might be.
I made a program that listens to modem messages and then according to these messages the program changes the computer's redstone outputs.
There is a set iterval while the messages may arrive (8s), but in reality they always arrive in 5s.

The code can be found here: r_mst. At line 41 I get an "Attempt to call nil" error. What am I doing wrong?

I'm sure there are many more erros in the program, but I kinda got stuck at this point.
Thanks for help!
KingofGamesYami #2
Posted 25 May 2015 - 12:21 AM
At a random guess, I'd say os.cancelTimer isn't a function in whatever version of CC you have.
MatthewC529 #3
Posted 25 May 2015 - 12:29 AM
Possibly doesn't exist, the alternative is to only acknowledge the current Timer ID by using the second value returned by os.pullEvent() for timer events. pullEvent returns "timer" and the Timer ID for the timer that expired, you can use that to ignore unrelated Timer events.
Bomb Bloke #4
Posted 25 May 2015 - 12:47 AM
… which you should be doing anyway.

if event == "timer" and side == timerID then --not all messages have arrived
eastar #5
Posted 25 May 2015 - 01:04 AM
The CC webapge about the os API doesn't say that the os.cancelTimer() function was added at a later version of CC. (I use CC 1.5) Are you sure about this?
Bomb Bloke #6
Posted 25 May 2015 - 01:23 AM
Beats me when it was added, but it doesn't exist in 1.5.

But that's fine, because you totally don't need to use it. Just make sure that whenever you're attempting to catch a timer event, that the associated ID matches with the timer you're currently looking for.
eastar #7
Posted 25 May 2015 - 01:33 AM
Alright! Thank you very much!
Thanks to all! :)/>