function mineup()
until turtle.detectUp() == false then
turtle.digUp()
turtle.up()
else
until turtle.detectDown() == true then
turtle.down()
end
end
end
function ddf()
if turtle.detect() == true then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
function checkfuel()
if turtle.getFuelLevel <= 10 then
turtle.select(1)
turtle.refuel()
end
end
print("Hello. Welcome to the Cheesety210 Tree cutting program")
print("Please put your fuel in the first slot.")
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
clear
print("I, your turtle, should be placed at the bottom of a tree")
print("right next to the tree. A diagram is below.")
print(" [ ] = A log, and T is the turtle")
print("[ ] [ ] ")
print("[ ] [ ] ")
print(" T ")
print(" What is the width/length of the tree? In the example above it's 2.")
local length = read()
if length == 1 then
checkfuel()
ddf()
mineup()
end
if length == 2 then
checkfuel()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.forward()
end
if length == 3 then
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnLeft()
ddf()
mineup()
checkfuel()
turtle.turnLeft()
ddf()
mineup()
checkfuel()
ddf()
mineup()
end
print("I am done with this tree!")
I'm not exactly sure how to use until's in a function.
7 replies to this topic
#1
Posted 01 April 2013 - 03:59 AM
I'm getting an error on line 3about an end expected. Here is my code
#3
Posted 01 April 2013 - 04:43 AM
TheCoryKid, on 01 April 2013 - 04:38 AM, said:
Not this:
But this:
All you had to do was search Google for "Lua repeat": magic.
until turtle.detectUp() == false then turtle.digUp() turtle.up() else
But this:
repeat turtle.digUp() turtle.up() until turtle.detectUp() == false
All you had to do was search Google for "Lua repeat": magic.
#5
Posted 01 April 2013 - 05:00 AM
The syntax for a repeat loop is this:
An exsample of this:
repeat
--Your code that will be repeated
until (condition that makes it stop)
An exsample of this:
local x = 1
repeat
x = x + 1
print(x)
until x == 10
#6
Posted 01 April 2013 - 05:08 AM
sjele, on 01 April 2013 - 05:00 AM, said:
The syntax for a repeat loop is this:
An exsample of this:
repeat --Your code that will be repeated until (condition that makes it stop)
An exsample of this:
local x = 1 repeat x = x + 1 print(x) until x == 10
So my code would be:
function mineup() repeat turtle.digUp turtle.up until turtle.detectUp() == false repeat turtle.down() until turtle.detectDown() == true end
#7
Posted 01 April 2013 - 05:10 AM
Cheesety210, on 01 April 2013 - 05:08 AM, said:
sjele, on 01 April 2013 - 05:00 AM, said:
The syntax for a repeat loop is this:
An exsample of this:
repeat --Your code that will be repeated until (condition that makes it stop)
An exsample of this:
local x = 1 repeat x = x + 1 print(x) until x == 10
So my code would be:
function mineup() repeat turtle.digUp turtle.up until turtle.detectUp() == false repeat turtle.down() until turtle.detectDown() == true end
More like:
function mineup() repeat turtle.digUp() turtle.up() until turtle.detectUp() == false repeat turtle.down() until turtle.detectDown() == true end
#8
Posted 01 April 2013 - 05:11 AM
You forgot () after all your turtle.(something) calls.
This should work
[edit]Ninja'ed[/edit]
function mineup() repeat turtle.digUp() turtle.up() until turtle.detectUp() == false repeat turtle.down() until turtle.detectDown() == true end
This should work
[edit]Ninja'ed[/edit]
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











