Posted 30 July 2014 - 04:37 AM
Edit: SOLVED. Thanks to hilburn.
I'm a beginner using this mod to teach myself the basics of programming. After getting a decent, but inefficiently written Tree Farm program working, I decided to try writing something similar to the default "go" program (in terms of what it does, not how it's written) to make it a bit more efficient. Here's my code (in a turtle):
Fairly self-explanatory what it's supposed to do. Put in a movement direction/type, and amount of times to do that movement, then it does that movement type that number to times.
The problem: It's cycling through all movement types. As in it goes, Up 2, Down 2, Forward 2, Back 2, Turn Left 2, Turn Right 2.
Obviously, I'm doing something wrong, but I have no idea what. It works fine if I only write the "up" and "down" sections, which is even more confusing to me.
Sorry if my format/layout isn't ideal either, kind of just making that up as I go.
I'm a beginner using this mod to teach myself the basics of programming. After getting a decent, but inefficiently written Tree Farm program working, I decided to try writing something similar to the default "go" program (in terms of what it does, not how it's written) to make it a bit more efficient. Here's my code (in a turtle):
Spoiler
local function Move(direction, amount)
if direction == up then
for i = 1, amount do
turtle.up()
end
end
if direction == down then
for i = 1, amount do
turtle.down()
end
end
if direction == forward then
for i = 1, amount do
turtle.forward()
end
end
if direction == back then
for i = 1, amount do
turtle.back()
end
end
if direction == left then
for i = 1, amount do
turtle.turnLeft()
end
end
if direction == right then
for i = 1, amount do
turtle.turnRight()
end
end
end
-- testing
Move(left, 2)
Fairly self-explanatory what it's supposed to do. Put in a movement direction/type, and amount of times to do that movement, then it does that movement type that number to times.
The problem: It's cycling through all movement types. As in it goes, Up 2, Down 2, Forward 2, Back 2, Turn Left 2, Turn Right 2.
Obviously, I'm doing something wrong, but I have no idea what. It works fine if I only write the "up" and "down" sections, which is even more confusing to me.
Sorry if my format/layout isn't ideal either, kind of just making that up as I go.
Edited on 30 July 2014 - 08:43 AM