Jump to content




Rednet issues :( [Can't find bug]


  • You cannot reply to this topic
8 replies to this topic

#1 moneymaster2012

  • Members
  • 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


#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, 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.

#3 moneymaster2012

  • Members
  • 38 posts

Posted 24 December 2015 - 08:40 PM

View PostLBPHacker, on 24 December 2015 - 08:38 PM, said:

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?

#4 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 24 December 2015 - 08:42 PM

View Postmoneymaster2012, on 24 December 2015 - 08:40 PM, said:

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?

#5 moneymaster2012

  • Members
  • 38 posts

Posted 24 December 2015 - 08:45 PM

View PostLBPHacker, on 24 December 2015 - 08:42 PM, said:

View Postmoneymaster2012, on 24 December 2015 - 08:40 PM, said:

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.

#6 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, 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.

#7 moneymaster2012

  • Members
  • 38 posts

Posted 24 December 2015 - 08:49 PM

View PostLBPHacker, on 24 December 2015 - 08:46 PM, said:

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.

#8 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, 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 by LBPHacker, 24 December 2015 - 08:54 PM.


#9 moneymaster2012

  • Members
  • 38 posts

Posted 24 December 2015 - 08:59 PM

View PostLBPHacker, on 24 December 2015 - 08:53 PM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users