Jump to content




working with os.startTimer

game computer api

5 replies to this topic

#1 cmdpwnd

  • Members
  • 128 posts
  • LocationHere

Posted 05 June 2015 - 03:36 PM

Alright so im trying to run a loop for X seconds where X is a func arg. Right now I have the variable init but I can't figure out where to put my os.pullEvent("timer") at because in the loop im returning but outside of the loop it would only run until the loop returned(I need it to be able to return multiple times). If I have the pullEvent just after return I get a 'end was expected to close if' error, I Just don't know where to put it at.

Code:

Original Question code snippet: http://pastebin.com/tYAPTthQ

Actual Function slightly diff from above: http://pastebin.com/8Rd0XCvJ

Edited by jacky500, 05 June 2015 - 07:45 PM.


#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 05 June 2015 - 04:38 PM

You almost got it. The only thing left to do is leave only one os.pullEvent without an event filter, so you could catch every event you need, and check what event it was.

#3 cmdpwnd

  • Members
  • 128 posts
  • LocationHere

Posted 05 June 2015 - 06:41 PM

View PostMKlegoman357, on 05 June 2015 - 04:38 PM, said:

You almost got it. The only thing left to do is leave only one os.pullEvent without an event filter, so you could catch every event you need, and check what event it was.

so like

mytimer = os.startTimer(waitTIme)
timer = {os.pullEvent()}

if timer == "timer" and timer[2] == mytimer then
blah
end

I just tried that out but its doing the same thing, Its like it just hangs waiting for the timer to finish even though the event isn't fired. If I run the same func without the timer it works fine but its just not continuing once it hits the pullEvent().

Heres the real code for reference.

http://pastebin.com/8Rd0XCvJ

Edited by jacky500, 05 June 2015 - 06:53 PM.


#4 biggest yikes

  • Members
  • 573 posts

Posted 05 June 2015 - 06:56 PM

View Postjacky500, on 05 June 2015 - 06:41 PM, said:

-snip-
if timer == "timer" and timer[2] == mytimer then
-snip-
I think you'd have to do
if timer[1] == "timer"
not
if timer == "timer"

Edited by Atenefyr, 05 June 2015 - 06:57 PM.


#5 cmdpwnd

  • Members
  • 128 posts
  • LocationHere

Posted 05 June 2015 - 07:44 PM

View PostAtenefyr, on 05 June 2015 - 06:56 PM, said:

View Postjacky500, on 05 June 2015 - 06:41 PM, said:

-snip-
if timer == "timer" and timer[2] == mytimer then
-snip-
I think you'd have to do
if timer[1] == "timer"
not
if timer == "timer"

Plz reference: http://pastebin.com/8Rd0XCvJ

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 05 June 2015 - 09:06 PM

You have 3 instances of os.pullEvent there;

line 3
line 7
line 14

Try to reduce this to a single os.pullEvent without any parameters. When utilizing multiple events, you cannot use a filter. Instead, do something like this:

while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" then
    --#stuff
  elseif event[ 1 ] == "modem_message" then
    --#other stuff
  end
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users