Jump to content




Problem With Rednetmessages

wireless help

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

#1 jeroentjuh99

  • Members
  • 15 posts

Posted 16 August 2013 - 02:49 PM

Hi,
I am trying to create an music-system using a computer, a turtle and rednet.
I made some code, but it doesn't seem to work:

computer:
Spoiler

turtle:
Spoiler

What I am trying to do is the following:
When you enter a number (1~16) on the computer, it sends it to the turtle. The turtle should read the message, and select the right slot.
It currently only selects slot 16, because the message send is 6.0. It doesn't matter what you type into the computer, the received message is always 6.0.

What is wrong?
Thank you for your time :)

#2 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 16 August 2013 - 03:13 PM

rednet.receive returns several parameters, not just the message being sent.

http://www.computerc.../Rednet.receive
You should change the line:
local msg = rednet.receive()
to:
local senderID, msg, distanceFromSender = rednet.receive()
because rednet.receive returns the channel that the message was sent on (which should be the id of the sender if the sender used rednet.send), the message sent, and the distance from the sending computer.

#3 jeroentjuh99

  • Members
  • 15 posts

Posted 16 August 2013 - 04:24 PM

Alright, changed it. I'll try it tomorrow!

#4 Pinkishu

  • Members
  • 484 posts

Posted 16 August 2013 - 05:30 PM

Also if you want to keep the code that way, you'll probably have to remove the local from the rednet.receive line

Or at least I think the way it currently is, the select function wouldn't even know about the msg received?

#5 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 17 August 2013 - 01:52 AM

View PostPinkishu, on 16 August 2013 - 05:30 PM, said:

Also if you want to keep the code that way, you'll probably have to remove the local from the rednet.receive line

Or at least I think the way it currently is, the select function wouldn't even know about the msg received?

You're certainly right! :)

#6 reububble

  • Members
  • 72 posts
  • LocationBehind you

Posted 17 August 2013 - 04:36 AM

Sometimes I get these float errors and the best thing to do is just floor it. I don't mean go really fast and be a hoon, I mean use the math.floor(x) to round off the number

#7 jeroentjuh99

  • Members
  • 15 posts

Posted 17 August 2013 - 04:54 AM

I'll try it without local then.

EDIT: thanks! It works now! Now I have to do some tweaking, but I found some useful stuff around here.

Edited by jeroentjuh99, 17 August 2013 - 05:16 AM.


#8 jeroentjuh99

  • Members
  • 15 posts

Posted 17 August 2013 - 09:00 AM

I changed function receive() to this:
function receive()
if not rednet.isOpen("right") then
rednet.open("right")
end
senderID, msg, distanceFromSender = rednet.receive()
term.clear()
term.setCursorPos(1,1)
term.write(msg)
end
because I noticed every time I loaded my savegame, the turtles modem was off-line. It still is. How do I change that?
It's weird that I have to terminate the startup program and reboot the turtle every time I load the savegame :/

#9 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 17 August 2013 - 01:27 PM

That is rather strange. My only suggestion would be to have the startup file open the modem for the turtle, run your script, then close the modem.

Something like this:
rednet.open ("right")
shell.run ("your_program")
rednet.close ("right")


#10 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 17 August 2013 - 08:24 PM

View Postjeroentjuh99, on 17 August 2013 - 09:00 AM, said:

I changed function receive() to this:
function receive()
if not rednet.isOpen("right") then
rednet.open("right")
end
senderID, msg, distanceFromSender = rednet.receive()
term.clear()
term.setCursorPos(1,1)
term.write(msg)
end
because I noticed every time I loaded my savegame, the turtles modem was off-line. It still is. How do I change that?
It's weird that I have to terminate the startup program and reboot the turtle every time I load the savegame :/

Computers reboot when you reload the savegame - there's nothing you can do about that.
I'll bet your modem also goes off-line if you reboot the turtle. You should fix that by opening the modem in your program.

#11 jeroentjuh99

  • Members
  • 15 posts

Posted 18 August 2013 - 04:06 AM

View Postimmibis, on 17 August 2013 - 08:24 PM, said:

View Postjeroentjuh99, on 17 August 2013 - 09:00 AM, said:

I changed function receive() to this:
function receive()
if not rednet.isOpen("right") then
rednet.open("right")
end
senderID, msg, distanceFromSender = rednet.receive()
term.clear()
term.setCursorPos(1,1)
term.write(msg)
end
because I noticed every time I loaded my savegame, the turtles modem was off-line. It still is. How do I change that?
It's weird that I have to terminate the startup program and reboot the turtle every time I load the savegame :/

Computers reboot when you reload the savegame - there's nothing you can do about that.
I'll bet your modem also goes off-line if you reboot the turtle. You should fix that by opening the modem in your program.
It is getting opened at the start of the program. The first thing it does when the turtle (re)boot is checking if the modem is open, and if not, it opens it.
The weird thing in that is couldn't be opened.

But somehow it managed to fix itself. It starts online now.

Edit: It did not fix itself. I still get troubles getting the modem on. Any ideas?

Edited by jeroentjuh99, 18 August 2013 - 06:53 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users