Jump to content




[solved] os.pullevent preventing a file write?


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

#1 CreeperGoBoom

  • Members
  • 91 posts

Posted 23 October 2014 - 08:41 AM

warning, the link leads to fully working code, but as a comparison tool:
http://pastebin.com/F4AeRpvA
if i change line 71 and 72 to this:
event={os.pullevent}
print("by default, 1:true or 2:false? press desired number")
if event[1]=="key" then
if event[2]==2 then
state=true
setstr(config,state)
elseif event[2]==3 then
state=false
setstr(config,state)
end
end

the setstr after disk is read is completely bypassed (line 97 in link), however if i change the code above to the code in the link everything works fine, so my next question, how do i consecutively use pullEvent without code being bypassed mysteriously?

this is for a one time configuration of a pc

if anyone has any ideas that would be appreciated, right now its doing my head in so

thanks in advance :D :thumbsup:

edit: if im doing something wrong, then i also face the same issue in a larger project of mine o.0

Edited by CreeperGoBoom, 23 October 2014 - 09:13 AM.


#2 Bomb Bloke

    Hobbyist Coder

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

Posted 23 October 2014 - 08:55 AM

os.pullevent will be nil. Did you mean os.pullEvent()?

It may also pay to implement a check to deal with scenarios where the event isn't a key event, as your code will indeed merrily carry on its way if it's not. Eg:

print("by default, 1:true or 2:false? press desired number")
local event
repeat event = {os.pullEvent()} until event[1] == "key" and event[2] > 1 and event[2] < 4
setstr(config, event[2] == 2)

Edit: Ah, I see the bit you're concerned about. Yeah, you need to deal with situations where you don't get the right event type. For example, pressing a button generates both a key and a char event; so when the first question is answered, the resulting char event remains in the event queue and confuses your second question.

In any case, implementing code along the lines of what I demonstrated above will sort it out.

Edited by Bomb Bloke, 23 October 2014 - 09:03 AM.


#3 CreeperGoBoom

  • Members
  • 91 posts

Posted 23 October 2014 - 09:12 AM

thanks Bomb Bloke, yes thats what i meant pullEvent :D

thanks mate that solved my problem, whew thats gonna save me a few headaches, +kudos :D





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users