23 posts
Posted 22 February 2014 - 06:49 PM
Hello, I wondered how I could loop this code until whenever it receives a rednet message which says "startup".
I tried this but it doesn't loop:
while true do
local side = {"right", "left", "top", "bottom", "front", "back"}
local random_side = side[math.random(1, #side)]
rs.setOutput(random_side, true)
sleep(math.random(0.5, 1))
rs.setOutput(random_side, false)
sleep(math.random(0, 0.5))
id, event, message = os.pullEvent()
if event == "redstone_message" and message == "startup" then
return
end
end
89 posts
Location
getServer().getPlayer("Thib0704").getLocation();
Posted 22 February 2014 - 07:38 PM
1. What are you trying to do?
2. Are you using REDNET or REDSTONE ??
114 posts
Posted 22 February 2014 - 07:45 PM
if you're trying to use rednet then use this:
while (message ~= "startup") do
event, replyChannel, message, senderDistance = os.pullEvent("modem_message")
end
Edited on 22 February 2014 - 06:50 PM
23 posts
Posted 22 February 2014 - 08:08 PM
correction :
if event == "rednet_message" and message == "startup" then
return
end
I'm trying to run programs through another pc via rednet, where the first pc runs a program, and if input is "start", this script starts on another pc which sends random redstone signals to redstone lamps, but I want it to loop until it gets an message saying "startup" which starts up the startup-script. Planning on making a concert where a main computer turns on blinking lights.
7508 posts
Location
Australia
Posted 22 February 2014 - 08:18 PM
okay so I need to correct you on some incorrect thinking here…
When a redstone signal changes for a computer (whether it's on or off) it will fire an event named
redstoneWhen a message is sent from one computer to another (via wired or wireless) it will fire two events (1 in older ComputerCraft) named
modem_message and
rednet_message; in the case of how you are using your code you should make use of the
rednet_message event
Edited on 22 February 2014 - 07:18 PM
89 posts
Location
getServer().getPlayer("Thib0704").getLocation();
Posted 23 February 2014 - 09:50 AM
You want something like this:
local running = true
local modemSide = "right" -- Modem side.
local outputSide = "left" -- Redstone output side.
local toggleMode = true
rednet.open(modemSide)
while running do
id,msg,dist = rednet.receive()
if msg == "toggle" then
rs.setOutput(outputSide, toggleMode)
if toggleMode then toggleMode = false else toggleMode = true end
end
end
Edited on 23 February 2014 - 08:51 AM
1852 posts
Location
Sweden
Posted 23 February 2014 - 10:57 AM
I just want to point out to the OP that you're using
os.pullEvent wrong, Since it returns the event first.
And it's rednet, Not redstone in this case
Example
local sides = rs.getSides() -- Get the redstone sides
while true do
local event, id, message = os.pullEvent( "rednet_message" )
if message == "blah"
local side = sides[math.random( 1,#sides )]
if rs.getOutput( side ) then
rs.setOutput( side, false)
else
rs.setOutput( side, true )
end
end
end
Edited on 23 February 2014 - 09:58 AM
23 posts
Posted 23 February 2014 - 11:48 AM
Alright, thanks everybody :)/>