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

Turtle cordinates problem

Started by ligglo, 13 April 2012 - 08:00 AM
ligglo #1
Posted 13 April 2012 - 10:00 AM
I can't see the problem with the code here. There isnt an error, but the code is skipping from 0 to 2, skipping the 3 between. It is supposed to count 0,3,2,1, then back and in that order. rotval is the rotation value of the turtle, like the f in minecraft coords. I will have a very similar one for turtle.turnRight(). Solved the problem, the only one remaining is how to work monitors, and how to send information from my turtle to my computer.

if button == 30 and rotval == 0 then
turtle.turnLeft()
rotval = 3
end
if button == 30 and rotval == 1 then
turtle.turnLeft()
rotval = 0
end
if button == 30 and rotval == 2 then
turtle.turnLeft()
rotval = 1
end
if button == 30 and rotval == 3 then
turtle.turnLeft()
rotval = 2
end

–Detects turning left
Luanub #2
Posted 13 April 2012 - 10:38 AM
Its due to the logic in your script. Since you are using all if's it checks each one every time the sequence is ran. so if its starts at 0 it changes to 3, then when it hits the if rotval == 3 it changes to the 2 appearing to have skipped the 3.

do this

if button == 30 and rotval == 0 then
turtle.turnLeft()
rotval = 3
elseif button == 30 and rotval == 1 then
turtle.turnLeft()
rotval = 0
elseif button == 30 and rotval == 2 then
turtle.turnLeft()
rotval = 1
elseif button == 30 and rotval == 3 then
turtle.turnLeft()
rotval = 2
end
Slev7n #3
Posted 13 April 2012 - 03:23 PM
to send information from the turtle to computer use rednet:

rednet.open("right") –(to open rednet port)

rednet.broadcast(message) –(this sends the message to every system that receives and is in range)
or
rednet.send(ID,message) –(just send the message to the computer with the specific ID)
ID is a int and message is a String

to receive a message with rednet use:rednet.open(side)
rednet.receive(t) –(t is the time for that it receives. if there is nothing than it receives untill it gets a message)
ligglo #4
Posted 13 April 2012 - 10:35 PM
Thanks for all the help everyone. I will get to work on making my program now.