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

Receiving and printing custom variables on rednet?

Started by moneymaster2012, 18 December 2015 - 05:59 PM
moneymaster2012 #1
Posted 18 December 2015 - 06:59 PM
I am trying to make and test out a banking system, but I do not know how to receive and print a custom variable from another computer. My code doesn't work.

Here is my code to work off from:

rednet.open("left")
rednet.receive(withdraw)  --That's what the variable in the sending computer is
withdraw = wamount
print(wamount) -- except this doesn't print the custom variable from the other computer
Yevano #2
Posted 18 December 2015 - 07:17 PM
Take a look at the wiki and you'll find that receive doesn't necessarily require any arguments. You don't want to give it the variable you want the data in, you need to get the returned values from receive.

The way rednet works is one computer will send a message and other computers which are waiting for a message will receive the message. From your other computer that you need to get data from, it should send you the data, and you should listen for that message on the receiving computer.

Sending computer
rednet.send(receiverID, withdraw)

Receiving computer
local id, msg = rednet.receive()
if id == bankComputerID then
	wamount = msg
end
--# Most likely you'll run this in a loop so that if you receive a message from the wrong computer, you can continue listening.
Edited on 18 December 2015 - 06:17 PM