38 posts
Posted 24 December 2015 - 08:27 PM
I am trying to make an atm program using turtles, and my withdraw function and rednet is not working. Please take a look. The error says: rednet:87: Expected number
Computer (withdraw):
local function withdraw()
clear()
print("Enter the amount you want to withdraw.")
term.setCursorPos(1,5)
write"$ "
amount = read()
rednet.send("entered")
rednet.send(amount)
clear()
textutils.slowPrint("Iron successfully withdrawn.")
sleep(3)
os.reboot()
end
Turtle (withdraw):
elseif message == "entered" then
turtle.select(9)
id, message = rednet.receive()
turtle.drop(amount)
turtle.select(1)
os.reboot()
end
758 posts
Location
Budapest, Hungary
Posted 24 December 2015 - 08:38 PM
rednet.send requires the ID of the recipient of the message
and the message, not just the message alone. There is a way to simply send messages without using an ID though, rednet.broadcast does that.
rednet.send(someID, "entered") -- you'll need to set someID to a valid number there
Check the
rednet API page for more info.
38 posts
Posted 24 December 2015 - 08:40 PM
rednet.send requires the ID of the recipient of the message
and the message, not just the message alone. There is a way to simply send messages without using an ID though, rednet.broadcast does that.
rednet.send(someID, "entered") -- you'll need to set someID to a valid number there
Check the
rednet API page for more info.
I didn't need to do that in my other functions. And I could just use rednet.broadcast() for now. Any other ideas?
758 posts
Location
Budapest, Hungary
Posted 24 December 2015 - 08:42 PM
I didn't need to do that in my other functions.
You didn't? Now that's curious. Mind showing some code that manages to call
rednet.send without an ID and doesn't crash?
38 posts
Posted 24 December 2015 - 08:45 PM
I didn't need to do that in my other functions.
You didn't? Now that's curious. Mind showing some code that manages to call
rednet.send without an ID and doesn't crash?
My bad. I meant to say I used rednet.broadcast(), not rednet.send(). Rednet.broadcast() doesn't need to have an id.
758 posts
Location
Budapest, Hungary
Posted 24 December 2015 - 08:46 PM
Oh, alright then. So is this fixed now? I'm asking because you asked for other ideas. Also because the code running on the turtle never sets amount, which might cause problems.
38 posts
Posted 24 December 2015 - 08:49 PM
Oh, alright then. So is this fixed now? I'm asking because you asked for other ideas. Also because the code running on the turtle never sets amount, which might cause problems.
Right now I added
amount = message
but I still get the same error.
758 posts
Location
Budapest, Hungary
Posted 24 December 2015 - 08:53 PM
The same error? How? Based on what you just said, there shouldn't be a rednet.send call in your program at all.
Ah, okay, I seem to have misunderstood. So, have you replaced rednet.send with rednet.broadcast or have you decided to supply rednet.send with a valid recipient ID instead?
Edited on 24 December 2015 - 07:54 PM
38 posts
Posted 24 December 2015 - 08:59 PM
The same error? How? Based on what you just said, there shouldn't be a rednet.send call in your program at all.
Ah, okay, I seem to have misunderstood. So, have you replaced rednet.send with rednet.broadcast or have you decided to supply rednet.send with a valid recipient ID instead?
Ohhh. My. Gosh. I am so sorry. I was misunderstood. You were trying to point out that I put rednet.send instead of rednet.broadcast. I am such a dummy -_-/> . Thank you.