7 posts
Posted 29 May 2012 - 01:22 AM
How would I make a time running program? This is what I have so faer
os.startTimer(1) – start5 second timer
X = 0
local, event, p1 == os.pullEvent("timer") – wait for a timer event
if p1 == "timer" then – check to make sure the timer went off
x = x+1
end
864 posts
Location
Sometime.
Posted 29 May 2012 - 05:30 AM
I don't think you can pull an event, set a variable for the timer then do an if command.
Example:
v = os.startTimer(1)
x = 0
if v == 0 then
x = x + 1
end
I'm not sure on this but when you find out please tell me because i think this could be useful.
1111 posts
Location
Portland OR
Posted 29 May 2012 - 05:45 AM
I don't think you can pull an event, set a variable for the timer then do an if command.
Example:
v = os.startTimer(1)
x = 0
if v == 0 then
x = x + 1
end
I'm not sure on this but when you find out please tell me because i think this could be useful.
wrong you can pull event. You will want to set it to 5 instead of 1 and the first x should be lowercase since lua is case sensitive. What you have should work
os.startTimer(5) -- changed to 5, this works the same as a sleep, enter the number of seconds you want to the timer to run for.
local x = 0 -- set as local and changed to lowercase to match the math below
local, event, p1 == os.pullEvent("timer") -- wait for a timer event
if p1 == "timer" then -- check to make sure the timer went off
x = x+1
end
Edited on 29 May 2012 - 03:53 AM
52 posts
Posted 29 May 2012 - 08:27 AM
Line 3, you have a comma immediately after local
Line 3, you're using "==" (Comparison) rather than "=" (Assignment)
Line 4, your "p1" should be "event" (You're checking the event, not the arguments)
I think it's also unnecessary, passing "timer" to os.pullEvent should filter it properly
1111 posts
Location
Portland OR
Posted 29 May 2012 - 08:58 AM
the p1 var will also capture "timer" when the timer goes off, most people check against it to ensure they got the right event. Also having it filter timer will help prevent key strokes and other events from setting it off, hopefully preventing a timer event being missed. Without the filter you would want your if statement to look like
if event == "timer" and p1 == "timer" then
52 posts
Posted 29 May 2012 - 09:10 AM
write( "n"..tostring(e).." - "..tostring(p1) )
Not sure, but that
might a table, not a string :)/>/>
2447 posts
Posted 29 May 2012 - 09:23 AM
The timer returned by os.startTimer is just an empty table - it is done this way as a table is guaranteed to be unique. You will just need to check that param1 returned by os.pullEvent is the same table object.