Jump to content




How to send programs to turtles with rednet


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

#1 Joe3000

  • Members
  • 44 posts

Posted 16 August 2012 - 06:07 AM

Ok, first off, im new to this, im a total noob, and i want to learn how to do this, so far what i know makes this mod really fun. Back to my question, I am trying to be able to control my turtle using rednet and a computer. What I thought of is something along the lines of this just to make the turtle go forward to see if it would work

Turtle:
rednet.recieve()
if message == "turtle forward" then
turtle.forward()
else
end

Again, I am a total noob and this seems way to easy to work... I cant get it to work but how would I?

Also a secondary question, where can i learn some more of the commands? I just learned "for n=... do" and i finally found out "While not ..... do" but where can I learn more?

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 16 August 2012 - 06:21 AM

Try doing something like this

Computer
rednet.send(turtleid, "forward")

Turtle
local id, msg = rednet.receive() -- need to capture the rednet.receive() output in vars
if msg == "forward" then
  turtle.forward()
end


#3 Joe3000

  • Members
  • 44 posts

Posted 16 August 2012 - 06:24 AM

I still get an attempt to call nill error

#4 Kazimir

  • Members
  • 90 posts
  • Locationthat's no moon...

Posted 16 August 2012 - 06:26 AM

Read the wiki and tutorials on forum, there is everything necessary for a beginner

id, message = rednet.recieve()
if message == "turtle forward" then
turtle.forward()
end


#5 BigSHinyToys

  • Members
  • 1,001 posts

Posted 16 August 2012 - 06:26 AM

replace turtleid with a number the Turtles ID you can get this by running "ID" program

#6 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 16 August 2012 - 06:41 AM

have you even opened a modem?

#7 Joe3000

  • Members
  • 44 posts

Posted 16 August 2012 - 06:46 AM

yes i have opened the modem and i have replaced turtleid with the turtles id.... still doesnt work....

#8 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 16 August 2012 - 06:49 AM

Do this to check and make sure the turtle is receiving the message

local id, msg = rednet.receive()
print("ID is "..id)
print("Message is "..msg)

If you could post the current code you are using and I'll take a look at it for errors.

#9 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 16 August 2012 - 06:50 AM

and you could just use loadstring, eg:

CLIENT
Spoiler

That way it will just treat anything as a command and try to execute it, this could be a problem as you would then be executing broadcasted messages too so instead you tell it to unserialize the message and then check if the first value is a certain keyword, if so then it executes the second value. now you send it serialized tables from the host PC and you're sorted, this way you can execute almost any lua script (a few don't work, I think shell.run() is one of them)

#10 Pharap

  • Members
  • 816 posts
  • LocationEngland

Posted 16 August 2012 - 08:25 AM

Ok, enough confusion:

Turtle(must be activated before computer)
rednet.open("right") --modem is always on the right side of the turtle
while true do --activates endless loop
local id, msg == os.pullEvent("rednet_message") -- when a message is received, these variables are written to
if msg == "forward" then -- test message
turtle.forward() --corresponding action
elseif msg = "end" then -- other option
break --breaks out of endless loop
end -- end if
end -- ends a cycle of the loop

Computer:
rednet.open("top") --assuming modem is on top
while true do
term.clear() -- clear screen
term.setCursorPos(1, 1) -- reset cursor
print("Enter a command")
local input = read()
if input == "forward" or input == "end" then --checks input is valid
rednet.send(turtleid, input) --sends input to turtle
--alternatively, if there are multiple turtles running the turtle program above, use rednet.broadcast(input) to reach them all easily
else --anything that isn't an aforementioned condition
print("Invalid command")
sleep(2)
end

There, now even the most beginnerist beginners should understand (I hope)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users