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

[solved] os.pullevent preventing a file write?

Started by CreeperGoBoom, 23 October 2014 - 07:41 AM
CreeperGoBoom #1
Posted 23 October 2014 - 09: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 on 23 October 2014 - 08:13 AM
Bomb Bloke #2
Posted 23 October 2014 - 09: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 on 23 October 2014 - 08:03 AM
CreeperGoBoom #3
Posted 23 October 2014 - 10: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/>