202 posts
Posted 02 February 2013 - 07:09 PM
I have a door that I want to be able to be opened from the main computer and another computer with a rednet modem on it. I already know how to use rednet and all of the other things I will need but I need to know if there is a way to have my main computer waiting for touchscreen and rednet events at the same time. Being able to do this will allow me to open the door with the monitor next to it AND from another computer somewhere else. I wanted to try to do something like
event = os.pullEvent()
if event == "monitor_touch" then
--door stuff
elseif event == "rednet_message" then
--more door stuff
end
but for the touch screen functionality I need the parameters of the event and I don't know how to do this.
If someone could tell me a way to do this, that would be great!
Help is appreciated!
Thanks! :D/>
15 posts
Location
Pennsylvania, USA
Posted 02 February 2013 - 07:20 PM
You're on the right track.
In Lua, functions can return more than one value, and os.pullEvent() does exactly this.
There are some examples (and a list of what the event parameters are) in the documentation for
os.pullEvent().
202 posts
Posted 02 February 2013 - 07:31 PM
Oh, ok. Although I still don't understand how I could get the parameters for monitor_touch. For example:
event, side, xPos, yPos = os.pullEvent("monitor_touch")
I need the x and y position of where I touched. How would I do this if I am not directly waiting for a monitor touch event?
2005 posts
Posted 02 February 2013 - 07:44 PM
Don't specify an event type, or os.pullEvent() will discard all other event types till it gets the type specified.
202 posts
Posted 02 February 2013 - 08:08 PM
So if I put
event, senderId, msg, side, xPos, yPos = os.pullEvent()
and the event is a rednet message then it will ignore the other parameters?
475 posts
Posted 02 February 2013 - 08:16 PM
Well you would do:
event, p1, p2, p3 = os.pullEvent()
202 posts
Posted 02 February 2013 - 08:22 PM
I don't think I really understand the os.pullEvent(). If I need either the location of where I touched the monitor or the message that a computer sent to it, what sort of parameters would I put on os.pullEvent()? If I put them in a certain order will the computer know which one is which?
671 posts
Location
That place over there. Y'know. The one where I am.
Posted 02 February 2013 - 09:24 PM
As lieudsty said:
event, p1, p2, p3 = os.pullEvent()
If it was rednet_message p1 would be the senderId, p2 would be the msg and p3 would be the distance between the sender and the reciever in blocks, but you can ignore that.
If it was monitor_touch p1 would be the side, p2 would be the x and p3 would be the y.
Simple enough.