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

Help with an error

Started by grand_mind1, 20 January 2013 - 03:48 PM
grand_mind1 #1
Posted 20 January 2013 - 04:48 PM
So I have set up a computer for a money system I have created on my server that is supposed to log interactions and communicates with the stores.

local senderId, message = rednet.receive()
if message == "Alex" then
  money = 100
  print(message)
elseif message == "David" then
  money = 20000
  rednet.send(senderId, money)<------------------------------Line seven
  print(message)
end

senderId, message = rednet.receive()
if senderId == 33 then
  store = "Store1"
  if message == "Coffee" then
	print("A "..message.." was bought from "..store)
  elseif message == "Cookie" then
	print("A "..message.." was bought from "..store)
  end
elseif senderId == 41 then
  store = "Store2"
else
  store = "Unknown"
end
However when the computer gets a message from a store it presents me with the error: "rednet:350: string expected" This only happens after I add line 7. I was thinking that it was because the variable "senderId" is defined outside of the if statement, but that is probably not correct. Could someone please tell me what I am doing wrong? Help is appreciated!
Thanks! :D/>

Also, sorry if this has a bad title, I couldn't think of anything.
theoriginalbit #2
Posted 20 January 2013 - 05:01 PM
This is because rednet can only send strings… you are trying to send a number

do this on sending
rednet.send( senderId, tostring( money ) )

and this on receiving

id, msg = rednet.receive()
msg = tonumber( msg )