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

[Lua] [question] simple vertical dig&drop off program using excavate

Started by corruptblack, 08 September 2012 - 06:17 AM
corruptblack #1
Posted 08 September 2012 - 08:17 AM
so im trying to make a simple dig program using the built in excavate program, since excavate digs all the way down and comes back automatically I figure it would make it a whole lot easier to just run excavate then put in programing to unload.
This is what ive got so far

clear
shell.run("excavate" "3")
end

yea… seriously it took me almost 2 hours to figure out that i needed "" .
my problem now is that i cant get the arguement for excavate in i type in

but when i run this it tells me: bios:206: [string "dig"]:3: '='
expected

apart from running excavate i want to add the drop program this is what ive found
end
for dropSlot = 1, 9 do
turtle.select(dropSlot)
turtle.drop()
end

so my first question is is this even possible? and second how do I
get shell.run to work with an argument?/where am i missing an = ?

according to this it should be fine but… still something is wrong

http://www.computerc...h__1#entry13191
using turtle v1.3
Edited on 08 September 2012 - 06:47 AM
Luanub #2
Posted 08 September 2012 - 08:46 AM
You need to seperate the arguments with a comma

shell.run("excavate", "3")
corruptblack #3
Posted 08 September 2012 - 08:52 AM
You need to seperate the arguments with a comma

shell.run("excavate", "3")
nope i still get the same error :
to verify:

clear
shell.run("excavate", "3")
end
Mtdj2 #4
Posted 08 September 2012 - 09:41 AM
You dont need that end. Clear isnt defined as a function either, so replace "clear" with "shell.run("clear")
corruptblack #5
Posted 08 September 2012 - 10:29 AM
thanks new code is now:
shell.run("clear")
shell.run("excavate", "3")

turtle.turnLeft()
turtle.turnLeft()

for dropSlot = 1, 9 do
turtle.select (dropSlot)
turtle.drop()

end

everything works well, but when i add another
turtle.turnLeft()
turtle.turnLeft()
after the drop the turtle turns around drops, turns around drops again losing half of the items. how do i get him to finish excavating turn around once drop all items and turn around again to repeat?
Zoinky #6
Posted 08 September 2012 - 10:45 AM
Put the other turtle.turnLeft() after the end. If you put it before it will turn every time. Since it runs the code 9 times.


shell.run("clear")
shell.run("excavate", "3")
turtle.turnLeft()
turtle.turnLeft()

for dropSlot = 1, 9 do
turtle.select(dropSlot)
turtle.drop()
end

turtle.turnLeft()
turtle.turnLeft()

Also, I took out the space between turtle.selct(dropSlot) since I don't think it should be there. Not sure if it works either way.
corruptblack #7
Posted 08 September 2012 - 11:29 AM
thanks works perfectly
corruptblack #8
Posted 08 September 2012 - 11:47 AM
actually sorry is there a way to make it repeat 5 times?
corruptblack #9
Posted 08 September 2012 - 11:56 AM
print("How many times would you like to run the program?")
local amountOfTimes = tonumber(read())
while amountOfTimes > 0 do

shell.run("clear")
shell.run("excavate", "3")
turtle.turnLeft()
turtle.turnLeft()

for dropSlot = 1, 9 do
turtle.select(dropSlot)
turtle.drop()
end

turtle.turnLeft()
turtle.turnLeft()
amountOfTimes = amountOfTimes - 1
if amountOfTimes == 0 then – not needed
end

i stiched this together from another program with a repeat but it gives me
22: 'end' expected (to close 'while' at line 3)
corruptblack #10
Posted 08 September 2012 - 12:03 PM
print("How many times would you like to run the program?")
local amountOfTimes = tonumber(read())
repeat

shell.run("clear")
shell.run("excavate", "3")
turtle.turnLeft()
turtle.turnLeft()

for dropSlot = 1, 9 do
turtle.select(dropSlot)
turtle.drop()
end

turtle.turnLeft()
turtle.turnLeft()
amountOfTimes = amountOfTimes - 1

untill amountOfTimes == 0 then – not needed


modified but now i have 22: = not expected
Luanub #11
Posted 08 September 2012 - 09:29 PM
The error is due to the then in the until statement, it is not needed.
corruptblack #12
Posted 09 September 2012 - 09:13 AM
if i do that i get the error 20: 'until' expected (to close 'repeat' at line 3)
i need the untill statement :D/>/>
Lyqyd #13
Posted 09 September 2012 - 09:35 AM
This is a spelling error. Until only has one L. The line should be:


until amountOfTimes == 0
corruptblack #14
Posted 09 September 2012 - 10:08 AM
This is a spelling error. Until only has one L. The line should be:


until amountOfTimes == 0
lmfao thank you that was it
Final program for anyone whos interested:

print("How many times would you like to run the program?")
local amountOfTimes = tonumber(read())
repeat

shell.run("clear")
shell.run("excavate", "3")
turtle.turnLeft()
turtle.turnLeft()

for dropSlot = 1, 9 do
turtle.select(dropSlot)
turtle.drop()
end

turtle.turnLeft()
turtle.turnLeft()
amountOfTimes = amountOfTimes - 1

until amountOfTimes == 0
Cloudy #15
Posted 09 September 2012 - 11:29 AM
Ok, so you use a for loop - and a repeat loop which decrements a variable. WHY!

Instead if the repeat do
for i = 1, amountOfTimes do
-- code here
end