My quarrying turtle script.

  • Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here
  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Jharakn

New Member
Jul 29, 2019
25
0
0
Hello all,

I've been teaching myself LUA and my latest creation I think is half decent enough that I'll share it with you guys too see what you think and maybe get some improvements.

Its a smart quarrying script that will dig a square quarry down to bedrock but importantly will only dig every 3rd layer comparing the layers above and below it to a list of filtered materials and ignoring them if they are on the filter.

Firstly credit where credit is due, the code is all my own but a lot of inspiration came from AustinKK's OreQuarry program on the computercraft forums. I used that program but wished it could retain its progress if the turtle became unloaded, for example stepping into a different mystcraft dimension so set about trying to make my own. So I present Jharakn's Quarry program.

Features:
Smart Quarry technology (tm) - cut down on the quantity of cobble, gravel and dirt produced
Amazing Fuel Efficiency compared to a buildcraft quarry
GPS uplink to automatically calculate positions
Automatic Position Saving - quarry will automatically restart (you need to set the startup program)

Setup:
1) firstly you need a GPS satellite or tower, if you don't know how to set one up there's a good guide here.
2) Label your turtle otherwise it will forget its code when it becomes unloaded, simple type "label set <turtle name>" into the turtle.
3) Load my quarry code into the turtle, again computercraft by default has an pastebin importer build in just type "pastebin get WzkjzJwB <program name>" into the turtle.
4) set your turtle up like this the wooden chest is for fuel, coal works best as the turtle will be pulling it out the ground but anything that burns works, whilst a turtle can burn buckets of lava my fuelCheck program can't handle it as the empty buckets confuses it.
5) set up the inventory of the turtle like this, fuel in slot 16 and the items you want to turtle to ignore in the first slots, you can have more or less than 3, if you wanted your turtle to quarry dirt for example you could remove it, likewise if you wanted to ignore iron ore you could add that to the list.
6) create a startup file for the turtle so it starts up when it loads again, you could just use:
Code:
sleep(20) -- give the GPS satellites time to warm up
shell.run("<program name>")
but I prefer:
Code:
if fs.exists("QuarryInstructions") == true then
sleep(20) --give the GPS satellites enough time to warm up
shell.run("<program name here>")
else
print("no instructions found, ready for use")
end
7) once your set up just run the program, if it has no previous instruction it'll ask you what size of quarry to dig then start, creating a new file called "QuarryInstructions". If it does find the quarry instructions file it'll just set off from where you left it.
8) profit???

as an aside I've got a small program that will print the status updates the turtle broadcasts to the rednet as it goes, just plug this into a computer attached to a monitor and and wireless modem.
Code:
-- ************************************ --
-- Quarrying Turtle Monitoring Program --
-- By Jharakn                          --
-- ************************************ --
 
local monitor = peripheral.wrap("top")
 
rednet.open("left")
monitor.clear()
monitor.setCursorPos(1,1)
 
local line = {"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"}
 
while true do
        local senderId, message, distance = rednet.receive()
        print(message)
        --line.1 = line.2; line.2 = line.3; line.3 = line.4; line.4 = line.5; line.5 = line.6; line.6 = line.7; line.7 = line.8; line.8 = line.9; line.9 = line.10; line.10 = line.11; line.11 = line.12
        for i = 1,11 do
                line[i] = line[i+1]
        end
        line[12] = message
        for i = 1,12 do
                monitor.setCursorPos(1,i)
                monitor.clearLine()
                monitor.write(line[i])
        end
 
end
also here

so try it out and let me know what you think.
 

Philderbeast

New Member
Jul 29, 2019
3
0
0
gave this ago and its rubbish.....

the basic concept is great but it never resumes correctly from being unloaded. not sure why so ill have a look at the code and see what i can find, but dont use this as a set and forget quarry script as it is, you will lose your turtle and a lot of resources
 

Saice

New Member
Jul 29, 2019
4,020
0
1
Ever since I found about the refuel all and label commands I just load my turtle up stuffed to the gills with lava buckets refuel all and then it will be days before I have touch any refueling at all.
 

eggdropsoap

New Member
Jul 29, 2019
4
0
0
This is great! I love Lua and turtles, and I'm not so happy with BC (especially since the changes that make conductive pipes easy to blow up when trying to power machines), so this suits my preferred style perfectly. There's a few modifications I want to make, such as allowing turtles to use charging pads, but for now a chest of charcoal is plenty. It's so satisfying to watch it go back and forth, punching a hole in the world and bringing me the goodies, and then intelligently picking up where it left off.

I did figure out why Philderbeast was having trouble restarting the turtles. There's a typo in the preferred startup script: wait() isn't a function so it returns nil -- it should be sleep(20) instead, like in the simple version right above it.
 

Jharakn

New Member
Jul 29, 2019
25
0
0
Wow I'd forgotten all about this thread until recently. Thanks for spotting the bug eggdropsoap I'll correct the first post, and I didn't know you could use charge stations for turtles. I'll look into that and maybe add support for stations into the functions.

Since the original post I've been trying to correct bugs as I go along, squished a few I think where the turtle could get stuck as it mines bedrock and I've tried to add some extra chatter the turtle broadcasts so if you've got a monitor set up the turtle should keep you well informed as to where it is and what its doing.

If anyone has any more features they thing would be nice let me know and I'll try to incorporate them as I lean more about LUA.
 

Philderbeast

New Member
Jul 29, 2019
3
0
0
This is great! I love Lua and turtles, and I'm not so happy with BC (especially since the changes that make conductive pipes easy to blow up when trying to power machines), so this suits my preferred style perfectly. There's a few modifications I want to make, such as allowing turtles to use charging pads, but for now a chest of charcoal is plenty. It's so satisfying to watch it go back and forth, punching a hole in the world and bringing me the goodies, and then intelligently picking up where it left off.

I did figure out why Philderbeast was having trouble restarting the turtles. There's a typo in the preferred startup script: wait() isn't a function so it returns nil -- it should be sleep(20) instead, like in the simple version right above it.

not the issue i was having at all,

due to the turtle not saving its position every move it was getting the locations wrong and not going back to the chests and it ends up throwing items everywhere and not getting fuel ;)
 

eggdropsoap

New Member
Jul 29, 2019
4
0
0
not the issue i was having at all,

due to the turtle not saving its position every move it was getting the locations wrong and not going back to the chests and it ends up throwing items everywhere and not getting fuel ;)
Is your GPS tower set up right? If it's not, the turtle can't save its position.
 

slay_mithos

New Member
Jul 29, 2019
1,288
0
0
Well, technically, it can, you just need to write a file with the program, but it's quite heavy to do it at each turn and move.

GPS is your friend if you want a turtle to be able to restart without massive amount of I/O that would slow the whole process, and potentially the game.
 

1726379897

New Member
Jul 29, 2019
32
0
0
Yooo Bro, ehm maybe need to fix bug: In Quarrry Program: Quarry:611: attempted to compare number with string expected, got number.
 

Jharakn

New Member
Jul 29, 2019
25
0
0
OK I'm back everyone, I've had a look at the two errors posted by 1726379897 and Jycs.

1726379897 with you the script was crashing out at the fuel checking function, is your server set so that turtles don't use fuel as that would cause it. I've updated a new version that shouldn't cause an error now if your server it set up that way. You will still need to put fuel in slot 16 changing that was a more complex issue for a later update but it'll just be a token gesture.

Jycs your one stumped me tbh, it was crashing at the part that reads the saved text file when the turtle restarts so it can continue on its progress, all I can sugest is firstly type the command "rm QuarryInstructions", that'll delete the saved state file and the turtle will behave as if you've just started a fresh new quarry and see if the error crops up again.

Hope this helps.