Jump to content




Help With A Os.pullevent() Code


  • You cannot reply to this topic
6 replies to this topic

#1 KDJSAIUH

  • Members
  • 35 posts

Posted 18 November 2013 - 12:54 PM

I made the following code and it is going to be used for a tower that lights lights at different stages and can be stopped, auto-run, auto-run stopped etc. But on the line that follows function define() the os.pullEvent() isnt working the way i want it to.

*NOTE:*
This code isnt finnished yet so dont critisize
Spoiler


#2 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 18 November 2013 - 01:43 PM

Well put quotes around key
elseif evt == "key"

Edited by Hellkid98, 18 November 2013 - 01:43 PM.


#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 November 2013 - 04:51 PM

Better yet, store the event somewhere. Just calling "os.pullEvent()" has your program block until the event is returned, you need to specifically capture its output in some variables if you want to refer to it later in the program.

Eg,

event,p1 = os.pullEvent()
if event=="key" and p1==keys.q then

I'm also unsure as to what "os.pullEvent(1.75)" is supposed to do.

You've asked for no "criticisms", but I feel at least one other tip is in order: When a function is called, it goes on the stack until it's finished. "Calling another function", including itself again, does not count as "finishing". Eventually the stack fills up, overflows, and the program crashes (you don't have unlimited RAM to keep track of function calls).

Hence if you want the "define()" function to be repeated over and over, don't have it call itself when it's done, put this at the bottom of your program instead:

while true do define() end

If you want your "define()" function to repeat early (eg after completing the "main()" function), then don't have "main()" call "define()", have "define()" use "return" directly after calling "main()".

Edited by Bomb Bloke, 18 November 2013 - 04:52 PM.


#4 KDJSAIUH

  • Members
  • 35 posts

Posted 21 November 2013 - 10:27 AM

The
os.pullEvent(1.75)
Is suppost to pull event for two seconds.and if there is no reply it will carry on but if there is it will stop

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 21 November 2013 - 10:44 AM

That's not at all how os.pullEvent works. The only argument it accepts is a string to use to filter events, so that it will only return that event type or a terminate event, if the coroutine is managed properly.

#6 Anavrins

  • Members
  • 775 posts

Posted 21 November 2013 - 10:45 AM

View Postkaioo1312, on 21 November 2013 - 10:27 AM, said:

The
os.pullEvent(1.75)
Is suppost to pull event for two seconds.and if there is no reply it will carry on but if there is it will stop

That's not how it works though, if you want something similar to that, you should call os.startTimer(1.75), before your pullEvent(), after 1.75 seconds it will push a "timer" event which you can deal with your "if" statement.

#7 KDJSAIUH

  • Members
  • 35 posts

Posted 24 November 2013 - 03:55 PM

Thanks





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users