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

os.pullEventRaw issue. maybe a bug?

Started by Goof, 14 December 2012 - 10:15 AM
Goof #1
Posted 14 December 2012 - 11:15 AM
Hello.

I was making a program which prevents ctrl t . I put this in the code:

Secured = true

if Secured then
local oldDog = os.pullEvent
os.pullEvent = os.pullEventRaw
end


and in the end:

if Secured then
os.pullEvent = oldDog
end



(im posting on my phone, so its hard to write.)

I really dont find any issues with this. But whhen i ran the program, it cant ctrl t. But when the program ended, the computer got a quick error, and then shuts down.

ehm. help me please!

thanks in advance

-mikk809h
Cloudy #2
Posted 14 December 2012 - 11:20 AM
You create a local inside the if statement. It goes out of scope when you end the statement. Hence when it comes time to set it back, oldDog is nil - causing the error.
Lyqyd #3
Posted 14 December 2012 - 11:22 AM
Not a bug with CC. Your code is doing exactly what you've told it to. You declare oldDog local to the scope of the if statement, so you shouldn't be surprised when you later find that it's gone out of scope when you try to use it again. When you set os.pullEvent to nil, you can certainly expect problems.
Goof #4
Posted 14 December 2012 - 11:25 AM
Ehm. Yeah, but if i took the local out, i still cant ctrl t when program is done? And i have tested that. I cant ctrl t when the program is done.
OmegaVest #5
Posted 14 December 2012 - 11:40 AM
Ah, no no no. What you want to do instead is this:


local oldDog
if Secured then
   oldDog = os.pullEvent
   os.pullEvent = os.pullEventRaw
--blah

That way, the variable is instantiated in the scope of the program outside the if statement. Unless you use oldDog somewhere else, in which case, I would make a table, but that's me.

But then you can just put it back normally.


BTW, this is what Cloudy was alluding to.
Goof #6
Posted 14 December 2012 - 11:50 AM
Well thanks for the response. I thinked my brain was trying to sleep, when i comming to this part of code,.. Lawl.
but thanks anyway :D/>