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

help to make a program

Started by hoidraar, 01 July 2015 - 07:56 PM
hoidraar #1
Posted 01 July 2015 - 09:56 PM
Hello, recently I'm playing minecraft with computercraft. I tryed to create my program for a mining turtle. The program works… but there is a problem: the turtle doesn't stop. I wrote this:

while true do
turtle.digUp ()
turtle.digDown ()
turtle.up ()
turtle.turnLeft ()
turtle.dig ()
turtle.turnRight ()
turtle.turnRight ()
turtle.dig ()
turtle.down ()
turtle.dig ()
turtle.turnLeft ()
turtle.turnLeft ()
turtle.dig ()
turtle.down ()
turtle.dig ()
turtle.turnRight ()
turtle.turnRight ()
turtle.dig ()
turtle.up ()
turtle.turnLeft ()
turtle.dig ()
turtle.forward ()
end

But I want that the turtle will stop when its inventory is full. And I also want that the turtle leave the mined items in a chest and then it returns to dig. How can I do? Or can you help me completing the program?
P.s. Sorry for the wrong translation but I don't speak english very well :unsure:/> :unsure:/> :unsure:/>
Rougeminner #2
Posted 02 July 2015 - 07:03 AM
well if you experiment around you can use if statements,some math and a tiny bit more programing and when your done you should have a working portion of code that uses atlas 2 if statements and a few variable references, speaking of references here you go

http://www,computerc...le.getItemCount : What you will Find there is 1 of the most important parts of your code you should have it check Turtle.getItemCount(9) and save it to a var like this

Slot9 = Turtle.getItemCount(9)

next your going to want to put an if in at the bottom to check if your Slot9 variable exceeds a certain number then stop like so

--This code only works for things that stack to 64
if Slot9 == 64 then
running = false
else
end
-- i will explain running = false in the next one

To terminate your while true do loops you need to create a variable that you can alter to make it stop so instead of "while true do print("foo-bar") end" do

running = true
while running do
print("foo-bar")
running = false
end
this will stop the while loop after its first run if you do

This code will keep going until it hits 64

running = true
-- For an example here i am going to set Slot9 Item count to 60
Slot9 = 60
while running do
--mining code goes here
if Slot9 == 64 then
running = false
print("inventory full Please Clean me out to continue."
else
-- Leave this empty and it will keep going
end
end

I hope this helped explain a bit if this doesn't work send me the code via PM and i will figure out where the problem is.
Edited on 02 July 2015 - 05:04 AM
flaghacker #3
Posted 02 July 2015 - 07:44 AM
I hope this helped explain a bit if this doesn't work send me the code via PM and i will figure out where the problem is.

Or even better, post it on the forum so we can all take a look and help.
hoidraar #4
Posted 02 July 2015 - 09:45 AM
thanks for your help but there is a problem: now the turtle repeats only one time the program. Where is the error?
while true do
turtle.digUp ()
turtle.digDown ()
turtle.up ()
turtle.turnLeft ()
turtle.dig ()
turtle.turnRight ()
turtle.turnRight ()
turtle.dig ()
turtle.down ()
turtle.dig ()
turtle.turnLeft ()
turtle.turnLeft ()
turtle.dig ()
turtle.down ()
turtle.dig ()
turtle.turnRight ()
turtle.turnRight ()
turtle.dig ()
turtle.up ()
turtle.turnLeft ()
turtle.dig ()
turtle.forward ()
running = true
– For an example here i am going to set Slot9 Item count to 60
Slot9 = 60
while running do
–mining code goes here
if Slot9 == 64 then
running = false
print("inventory full Please Clean me out to continue.")
else
– Leave this empty and it will keep going
end
end
end
Rougeminner #5
Posted 02 July 2015 - 04:41 PM
Ok so it looks like you mis understoud my how-to you need to to replace a bit. At the very top of your script create a variable name what ever you want for this example i will use running set running to true. Then replace your while true do with while running do. I will add to this post later i am on a mobile device which kinda restricts my options.