6 posts
Posted 20 December 2012 - 11:06 PM
hello :D/>
i have a problem in my CC creataion
i'm trying to send a redstone pulse via rednet, frim some reason it dosn't work..
here is my coeds:
sender:
and the if command goes on from 0 to 9.
receiver:
the problem is in the receiver, it doesn't reconize the input.
in the sender i see no problem..
plz help me :D/>
1214 posts
Location
The Sammich Kingdom
Posted 20 December 2012 - 11:08 PM
The "Programs" section is for released and working code and the "Ask A Pro" section is for getting help. Also, much easier to read code if it is on pastebin or if you copy and paste it into ['code']['/code'] tags.
818 posts
Posted 21 December 2012 - 01:40 AM
Your problem is at
local number = rednet.receive()
The function rednet.receive actually returns 3 variables(values). The first one being the ID of the sender, the second one being the actual message, and the third one being how long the message has traveled in meters(blocks if you will, same distance). So the best way to go around is to replace that line with this:
local senderID, number = rednet.receive()
And with that, you will be in pretty good shape.
7508 posts
Location
Australia
Posted 21 December 2012 - 01:46 AM
Also since you are saying in the sender this
local input = read()
if input == "0" then
rednet.broadcast("0")
elseif input == "1" then
rednet.broadcast("1")
elseif...... etc etc etc
change it to this
local input = read() -- this will read anything they input
if tonumber(input) then -- this uses the tonumber function to check if the input is a number
broadcast( input ) -- broadcast the input
else
print( "Please only enter a number" ) -- tell them they didn't input a number
end
EDIT: Using this means that if you ever add a new computer you dont have to edit your sender to add a new elseif statement, it will just work :)/> and if you want to validate the number they entered is within a range just do the following
while true do
input = read()
num = tonumber(input)
if num then -- this makes sure its not nil (i.e. they didn't enter text)
if num > 1 and num < 10 then
rednet.broadcast( input )
else
print("Not in correct range")
end
else
print("Not a number")
end
end