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

Turtle moving program with rednet help!

Started by LikeTheVideo!, 27 September 2012 - 11:37 PM
LikeTheVideo! #1
Posted 28 September 2012 - 01:37 AM
Hey,could someone tell me a basic code for a computer to send a message to a turtle to move forward how ever many blocks the user enters on the computer? I just started using comp.craft and want just a little headstart to using rednet :P/>/>. Thx!
Luanub #2
Posted 28 September 2012 - 03:39 AM
You pretty much just send a keyword to the turtle then use an if statement to check what was sent and then act appropriately.

Computer:

rednet.open("side") -- change side to the side your modem is on
rednet.send(turtleId, "forward")  -- change turtleId to the turtle computer id

Turtle:

rednet.open("right")
local id, msg = rednet.receive()
if msg == "forward" then
  turtle.forward()
end
LikeTheVideo! #3
Posted 28 September 2012 - 04:07 AM
@LuaManiac Thx,it worked :P/>/>!
LikeTheVideo! #4
Posted 28 September 2012 - 05:10 AM
Well,i just tryed it,its not working :P/>/>
Luanub #5
Posted 28 September 2012 - 05:27 AM
Can you post the code you used and the error that you get?
LikeTheVideo! #6
Posted 28 September 2012 - 05:39 PM
Well,i typed it exactly how you had it,changed 'turtle id' to my turtles id and all,but when i send the message,the turtle like…doesnt move…at all.., lol
LikeTheVideo! #7
Posted 29 September 2012 - 12:29 AM
does that code only affect regular turtles or does it do the other ones too?
Cranium #8
Posted 29 September 2012 - 12:47 AM
If you are using 1.41 or newer, you will need fuel for your turtles. This can be disabled in the configuration file. Otherwise, add some fuel like logs, wood or coal to the selected slot, and use turtle.refuel() to consume it and add it to the turtle.
LikeTheVideo! #9
Posted 29 September 2012 - 01:07 AM
@Cranium. Thanks,it works! one last thing : How can i make it go like…5 blocks instead of only 1? I tryed putting 5 in the 'turtle.forward()' parameters but it still goes only 1…
Luanub #10
Posted 29 September 2012 - 03:50 AM
You can make a function and/or use a for loop.

for loop only:

for x=1, 5 do
  turtle.forward()
end

Function with for loop:

local function forward(steps)
if not steps then steps = 1 end -- will use 1 if steps not specified
steps = tonumber(steps) -- makes sure that steps is a number
for x=1, steps do
  turtle.forward()
end
end

--then call it like this for 5 steps forward
forward(5)
LikeTheVideo! #11
Posted 29 September 2012 - 05:12 AM
@luanub Thanks! it worked. Now im trying to find the command to dig lol :P/>/>
Luanub #12
Posted 29 September 2012 - 05:21 AM
Check out this link for info on turtle commands. http://computercraft.info/wiki/index.php?title=Turtle_%28API%29