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

[Question]

Started by cptdeath58, 06 May 2014 - 11:12 PM
cptdeath58 #1
Posted 07 May 2014 - 01:12 AM
I have been trying to use the

os.pullEvent() = os.pullEventRaw()
in 1.56 but returns Unexcepted Symbol.
Is it supported in 1.56 or has it not been implemented?
Bomb Bloke #2
Posted 07 May 2014 - 01:16 AM
Brackets.
cptdeath58 #3
Posted 07 May 2014 - 01:31 AM
Brackets.
What about them?
Please explain…
Bomb Bloke #4
Posted 07 May 2014 - 01:34 AM
They shouldn't be there. You're trying to set the result of calling one function to the result of calling another - getting rid of the brackets will make it so that you're setting one function pointer to match that of another.
HometownPotato #5
Posted 07 May 2014 - 02:11 AM
Remove the parenthesis is what he means, so:
os.pullEvent = os.pullEventRaw;

So you set os.pullEvent to the os.pullEventRaw function, since calling it only returns what the function returns which will give you problems and not what you want.
cptdeath58 #6
Posted 07 May 2014 - 10:41 PM
They shouldn't be there. You're trying to set the result of calling one function to the result of calling another - getting rid of the brackets will make it so that you're setting one function pointer to match that of another.
Remove the parenthesis is what he means, so:
os.pullEvent = os.pullEventRaw;

So you set os.pullEvent to the os.pullEventRaw function, since calling it only returns what the function returns which will give you problems and not what you want.

Oh, For the record Brackets [], Parenthesis ()
Thank you, HometownPotato
Edited on 07 May 2014 - 08:42 PM
TheOddByte #7
Posted 07 May 2014 - 10:46 PM
Oh, For the record Brackets [], Parenthesis ()
That's good that you noticed that, Also when overriding the old os.pullEvent function you should create a backup of the old one

old_pullEvent = os.pullEvent -- Backup the old function
os.pullEvent = os.pullEventRaw -- Override it
os.pullEvent = old_pullEvent -- Restore it
This is good if you later want to restore the old one, otherwise you will always have ctrl+t prevention( if this is set as startup )
Dog #8
Posted 07 May 2014 - 10:53 PM
Out of curiosity, could you not also localize a variable so everything is restored when the program quits and exits (assuming you don't need to disable this somewhere within the program itself for other reasons)?

local os.pullEvent = os.pullEventRaw
Even if the program errored out, the reassignment would also 'go away' since it is local within the scope of the program, right?
Edited on 07 May 2014 - 08:55 PM
TheOddByte #9
Posted 07 May 2014 - 10:55 PM
Out of curiosity, could you not also localize a variable so everything is restored when the program quits and exits?

local os.pullEvent = os.pullEventRaw
Even if the program errored out, the reassignment would also 'go away' since it is local within the scope of the program, right?
Well if I'm correct that will error since you can't actually localize os.pullEvent
cptdeath58 #10
Posted 07 May 2014 - 10:55 PM
posssibly..
Dog #11
Posted 07 May 2014 - 10:56 PM
Well if I'm correct that will error since you can't actually localize os.pullEvent
Ahh…well so much for my genius plan :)/>
Edited on 07 May 2014 - 08:56 PM
CometWolf #12
Posted 07 May 2014 - 11:06 PM
It would error yes. Preferably you'd make a local os table containing the pullEvent function, then set that up to index to the global os table. However this will only affect direct usage of pullEvent within your script. Pre-defined functions like read would still point to the global version, so you'd be better of just overwriting that really.
cptdeath58 #13
Posted 07 May 2014 - 11:08 PM
isn't local used for setting variables?
Bomb Bloke #14
Posted 07 May 2014 - 11:13 PM
It is. A table or function pointer is stored in a variable, same as a number or a string.

Oh, For the record Brackets [], Parenthesis ()

Heh. For the record, not everyone speaks "American" English.
cptdeath58 #15
Posted 08 May 2014 - 10:47 PM
It is. A table or function pointer is stored in a variable, same as a number or a string.

Oh, For the record Brackets [], Parenthesis ()

Heh. For the record, not everyone speaks "American" English.
Sorry, didn't know you spoke a different language. I'll keep that in mind for now on.