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

Using os.pullevent for multiple events

Started by Andarno, 21 February 2013 - 11:54 PM
Andarno #1
Posted 22 February 2013 - 12:54 AM
I am trying to run a Startup program that waits for one of two actions.

1st action: A rednetmessage
2nd action: Someone clicking to enter the console.

I am using this code that i have written but the system runs the code but it does nothing when clicking it or receiving a rednet message.


rednet.close("back")
rednet.open("back")
while true do
event, message = os.pullEvent()
if event == "mouse_click" then
shell.run("Movelobby")
else
if event == "rednet_message" then
if message == "open door" then
rs.setOutput("left", true)
shell.run("sulobby")
end
end
end
end

Thankyou in advance
Edited on 22 February 2013 - 04:03 AM
Lyqyd #2
Posted 22 February 2013 - 05:03 AM
Split into new topic.
remiX #3
Posted 22 February 2013 - 05:14 AM
Use if … elseif… elseif… else… end


rednet.close("back")
rednet.open("back")

while true do
	event, message = os.pullEvent()
	if event == "mouse_click" then
		shell.run("Movelobby")
	elseif event == "rednet_message" then
		if message == "open door" then
			rs.setOutput("left", true)
			shell.run("sulobby")
		end
	end
end
LBPHacker #4
Posted 22 February 2013 - 05:14 AM
You can't detect users entering the terminal (I believe).
theoriginalbit #5
Posted 22 February 2013 - 05:21 AM
You can't detect users entering the terminal (I believe).
Nope, neither can you find a way to detect them leaving the terminal (the escape key does not send a key event)
LBPHacker #6
Posted 22 February 2013 - 05:25 AM
(the escape key does not send a key event)
SINCE 1.33 :D/> Thanks for fixing that!

But you can use a button that has to be pressed and use "redstone" event instead of "mouse_click". But never forget checking the redstone input, because "redstone" fires when the redstone switches off too…
theoriginalbit #7
Posted 22 February 2013 - 05:38 AM
because "redstone" fires when the redstone switches off too…
Doesn't specify a side either. just a generic "something has happened"