Posted 20 January 2014 - 11:11 PM
Following youtube tutorial for learning CC by BSGSamuel
I decided to use "if" statements in stead of the % used by the tutor.
My question is how to get the index/key of the orientations{} table and pass back to the variable "orientation"
For example if the program finished and the turtle is oriented to the South, I want assign 3 the "orientation" variable. So that the next time I rerun the code, the turtle knows it is facing South? hope my question is clear.
I decided to use "if" statements in stead of the % used by the tutor.
My question is how to get the index/key of the orientations{} table and pass back to the variable "orientation"
For example if the program finished and the turtle is oriented to the South, I want assign 3 the "orientation" variable. So that the next time I rerun the code, the turtle knows it is facing South? hope my question is clear.
orientation = 1
orientations ={"North", "East", "South", "West"}
function checkForO()
if orientation>4 then
orientation = 1
end
if orientation<1 then
orientation = 4
end
end
function left()
turtle.turnLeft()
orientation = orientation - 1
checkForO()
end
function right()
turtle.turnRight()
orientation = orientation + 1
checkForO()
end
for i = 1, 5 do
left()
print("I am facing " .. orientations[orientation])
end
--for i = 1, 3 do
--right()
--checkFor0()
--print("I am facing "..orientations[orientation])
--end