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

Rednet:350: string expected (Need help)

Started by gheotic, 03 February 2013 - 01:51 AM
gheotic #1
Posted 03 February 2013 - 02:51 AM
Im trying to make a program thats emits redstone if it get a signal from rednet but im also trying to make a function so if it get the signal (getState) then it send back the state but when i try that i just get this error rednet:350: string expected on the computer why?




local state = nil
local modem = "top"

local side = "left"

function Clear()
term.clear()
term.setCursorPos(1,1)
end

function RCslave()

while true do
local scrap, message = rednet.receive(5)

if message == "closeGate" then
redstone.setOutput(side,true)

Clear()


print("Close Gate")
state = closed

elseif message == "openGate" then
Clear()

redstone.setOutput(side,false)
print("Open Gate")
state = opened

elseif message == "getState" then
rednet.broadcast(state)
print("Broadcast state")


end
end
end

Clear()
rednet.open(modem)
textutils.slowPrint("Waiting for signal")
RCslave()
KaoS #2
Posted 03 February 2013 - 03:02 AM
use tostring on the message


rednet.broadcast(tostring(state))
gheotic #3
Posted 03 February 2013 - 03:31 AM
use tostring on the message


rednet.broadcast(tostring(state))


thank you so much :D/>
tesla1889 #4
Posted 03 February 2013 - 06:01 AM
–snip–

state = closed
--snip--
state = opened
--snip--

you have not defined the variables closed or opened, so when you set state to this, you're setting it to nil

either define closed as "closed" and opened as "opened" or change closed to "closed" and opened to "opened"