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

[Question]Turtle remembering

Started by solundor, 14 December 2012 - 05:23 AM
solundor #1
Posted 14 December 2012 - 06:23 AM
I'm Trying to make a Quarry like excavate I need to for how to make the Turtle remember where is the Charge Station is and if it can't mine any more,

im going to make it place an Ender Chest on top of it and drop this inventory in to it then digs it back up
Orwell #2
Posted 14 December 2012 - 06:52 AM
how to make the Turtle remember where is the Charge Station is and if it can't mine any more,
Those are two different things handled in different ways. To remember where the Charge Station is, you'd keep track of your coordinates in respect to the station. That basically means that everything you move, you update your position (x,y,z). When you do this nicely, you'd use some goniometry. (search for the different goto programs on the forums if you want some examples).

I'm not sure what you mean with knowing if you can still mine… What would be the condition on which you'd stop mining?
EDIT: If you mean like a maximum depth, that you'd just have a conditon somewhere along the lines of:

if currentY <= maxDepth then
  returnFromMining()
end
theoriginalbit #3
Posted 14 December 2012 - 01:10 PM
Another option for remembering where the station is, is to use GPS and have the charge stations x, y, z hard coded, then just move it there based on its location.

As for the still mine do you mean fuel level? if so I'd have it check the fuel level (turtle.getFuelLevel()) and check its distance away from the charge station. Since turtle.getFuelLevel() returns the amount of blocks it can move just have it so if the level + 10 (buffer just incase something unforeseeable happens) is equal to the distance away, go to the station.
solundor #4
Posted 15 December 2012 - 02:15 PM
I'm testing my mining Programs out so i switched the Fuel off so i only need the Turtle to remember it's location from restart, its using an Ender Chest to unload this is the code i got so far
Spoiler

local x,y,z = 0,0

function unload()
turtle.select(16)
turtle.placeUp()
if a = 1, 15 do
turtle.select(1)
turtle.dropUp()
end
turtle.select(16)
turtle.digUp()
end

function F()
while not turtle.forward() do
if turtle.dig() then
else
turtle.attack()
sleep(0.5)
end
end
x + 1
end

function FR()
turtle.turnRight()
while not turtle.forward() do
if turtle.dig() then
else
turtle.attack()
sleep(0.5)
end
turtle.turnRight()
y + 1
end

function FL()
turtle.turnLeft()
while not turtle.forward() do
turtle.dig()
end
turtle.turnLeft()
y + 1
end

function B()
while not turtle.forward() do
if turtle.dig() then
else
turtle.attack()
sleep(0.5)
end
end
x - 1
end

function BR()
turtle.turnRight()
while not turtle.forward() do
if turtle.dig() then
else
turtle.attack()
sleep(0.5)
end
turtle.turnRight()
y - 1
end

function BL()
turtle.turnLeft()
while not turtle.forward() do
turtle.dig()
end
turtle.turnLeft()
y - 1
end

function D()
turtle.turnLeft()
while not turtle.forward() do
turtle.dig()
end
turtle.turnLeft()
z - 1

end

the Ender Chest is in slot 16
what to you thing
Edited on 15 December 2012 - 01:20 PM
theoriginalbit #5
Posted 15 December 2012 - 02:24 PM
change

local x,y,z = 0,0,0
to this

local x,y,z = 0,0,0


otherwise from a quick skim its looking pretty good. if you wish I give you my expressed permission to look at the code for my BetterMiner program and use anything from it that you wish, it does check fuel, but awesome thing is, if fuel is turned off, it will never try to refuel.

my code can be found in the Programs forum under TheOriginalBIT's Programs or at my paste bin here http://pastebin.com/u/theoriginalbit
DaWooShit #6
Posted 18 December 2012 - 10:09 AM
Just save the coordinates to a file after each move and then load them each time the program starts?
DaWooShit #7
Posted 18 December 2012 - 11:11 AM
Here is my attempt at solving a similar problem, please note that this "quarry turtle program" is somewhat glitchy, but most of the times it will get past: server restarts, log outs and crashes, without failing. Most of the time…
http://pastebin.com/rKp6L2j9

You are welcome to copy any code you might like…
solundor #8
Posted 20 December 2012 - 12:10 AM
i see, is there an turtle API to see what direction it is facing

Spoiler


local x,y,z,f = 0,0,0,1

function unload()
turtle.select(16)
turtle.placeUp()
for a = 1, 14 do
turtle.select(a)
turtle.dropUp()
end
turtle.select(16)
turtle.digUp()
sleep(0.5)
turtle.select(15)
turtle.placeUp()
turtle.select(1)
turtle.suckUp()
turtle.refuel()
turtle.select(15)
turtle.digUp()
turtle.select(1)
sleep(0.5)
end

function chek()
for i=1 14 do
turtle.select(i)
if turtle.getItemCount(i) == 0 then
else
unload()
end
if turtle.getFuelLevel() == &amp;lt;10 do
unload()
end


function forward()
while not turtle.forward() do
if turtle.dig() then
else
turtle.attack()
sleep(0.5)
return
end
end
chek()
save()
x + 1
end


[color=#282828][font=helvetica, arial, sans-serif]
Edited on 19 December 2012 - 11:11 PM
solundor #9
Posted 26 December 2012 - 01:21 AM
bump
theoriginalbit #10
Posted 26 December 2012 - 02:41 AM
For now only if you have a compass turtle added by MiscPeripherals…
Orwell #11
Posted 26 December 2012 - 04:07 AM
I used a method using a torch and some dirt blocks once. It's just a bit elaborate.