local times = ""
local min = 500
local Level = turtle.getFuelLevel()
local FuelNeeded
sleep (1)
print ("Turtle will mine 1 block in front, and one to its left. Please use Ctrl+t to terminate and move the turtle")
sleep (2)
print ("Mining turtle wants to dig a 2x2 tunnel. Agree? 1 = Ok, 2 = No")
local input = read()
if input == "1" then
print ("Starting the program...")
sleep (1)
print ("How long do you wish to tunnel?")
times = read()
FuelNeeded = times*4+1
print ("Fuel needed to dig is "..FuelNeeded)
if turtle.getFuelLevel() < FuelNeeded then
print ("Fuel level is: "..turtle.getFuelLevel())
print ("Turtle is low on fuel. Do you wish to refuel? y/n")
local event, param1 = os.pullEvent("char")
if param1 == "y" then
turtle.select(1)
turtle.refuel()
else
print ("!Too low fuel for program to initiate!")
print ("Turtle rebooting!")
sleep (2)
os.reboot()
end
end
for i = 1, times do
turtle.dig()
while turtle.detect() do
turtle.dig()
end
while not turtle.forward() do
turtle.dig()
end
turtle.digUp()
while turtle.detectUp() do
turtle.digUp()
end
turtle.turnLeft()
turtle.dig()
while turtle.detect() do
turtle.dig()
end
turtle.turnRight()
while not turtle.up() do
turtle.digUp()
end
turtle.turnLeft()
turtle.dig()
while turtle.detect() do
turtle.dig()
end
turtle.turnRight()
turtle.down()
end
times = times+1
turtle.turnLeft()
turtle.turnLeft()
for i = 1, times do
while not turtle.forward() do
sleep (1)
end
end
end
turtle.turnLeft()
turtle.turnLeft()
Basic idea is: You start the program
Next you agree to start
Then you enter how long it will tunnel
After that, you put fuel in if required
Best part is that it will return to its starting position once it's done mining.
Will also handle sand and gravel very nicely
Again, very simple program.
How to get it:
* Make your mining turtle, and place it wherever you want to mine
* Open up the interface
* Type "pastebin get 9WuGM99n Dig" <---- this can be any name you want
* Press Enter
* Run the program, and enjoy the simple mining
I highly reccomend for everyone to install a chunk loader module if possible, as it's easy for the turtle to wonder off from the loaded chunks. It WILL stop, so be sure to either follow the turtle or to get a chunk loader on it
Anyway, have fun with this thing
-MyMusicManager
Changelog
Spoiler
V.0.2.1 - Shortened code by about 60 lines(!)
------------------------------------------
V.0.2.0 - Major update! Will now have the option to drop all items into either pre-placed chest, or place one down when done mining. Thanks A LOT to UNOBTANIUM for helping me with my code. You're awsome, dude!
------------------------------------------
v.0.1.6 - Will now build a bridge if no blocks below it. Will also always display current fuel
------------------------------------------
v.0.1.5.1 - I forgot like 1 line of code Derp
-------------------------------------------
v.0.1.5 - Tiny update with small improvements. Still a lot to do
-------------------------------------------
v.0.1.4 - Woah, this is moving fast. Will now show how much fuel is needed based on the length you wish to tunnel
-------------------------------------------
v.0.1.3 - More tweaks towards refueling. Bugs have been killed
-------------------------------------------
v.0.1.2 - Minor tweaks, added handling for gravel and sand
-------------------------------------------
v.0.1 - First release
Thanks A LOT to UNOBTANIUM for helping me so much with this code
WOA! 500 views in under a week? You guyes are awsome!
sweet little program you created there. I went over the code quickly and found some parts you might want to improve ;D
Spoiler
If you let the user chose from given options, it might be allways better to pull an event.
local id, key = os.pullEvent("key")
This gives back the key number of the pressed key. E.g. the number 1 on the keyboard is 2 for the pc. 2 is 3 and e.g. enter is 28.
This lets the player just use from the given options. You can detect a keypress with the following command:
if type(key) == "number" and key == 2 then -- if the number 1 key got pressed
-- do this
end
Refuel part: If the user writes "yes" it still does not refuel. Use the pull-event i showed you above ;D
Agree to start: This accually should work :s read() allways gives you a string but you are asking for a number. Change this to a pull-event as well.
Variables Level: This variables doesnt get changed if the user refuels the turtle. Even if the turtle has over 500 fuel in it, it shows less if it hasnt before.
This program doesnt handle falling sand and gravel. It has to detect if something is in front of it with a while loop and then digs it until it is gone.
sweet little program you created there. I went over the code quickly and found some parts you might want to improve ;D
Spoiler
If you let the user chose from given options, it might be allways better to pull an event.
local id, key = os.pullEvent("key")
This gives back the key number of the pressed key. E.g. the number 1 on the keyboard is 2 for the pc. 2 is 3 and e.g. enter is 28.
This lets the player just use from the given options. You can detect a keypress with the following command:
if type(key) == "number" and key == 2 then -- if the number 1 key got pressed
-- do this
end
Refuel part: If the user writes "yes" it still does not refuel. Use the pull-event i showed you above ;D
Agree to start: This accually should work :s read() allways gives you a string but you are asking for a number. Change this to a pull-event as well.
Variables Level: This variables doesnt get changed if the user refuels the turtle. Even if the turtle has over 500 fuel in it, it shows less if it hasnt before.
This program doesnt handle falling sand and gravel. It has to detect if something is in front of it with a while loop and then digs it until it is gone.
LIike I said, I'm quite the newbie on this kind of programming, but I'll look into this and try to improve the code. I know Direwolf20 has made some cool CC tutorials, I'll have a loot at those as well
Wouldnt it better if they turtle asks for the length of the tunnel first and then would calculate the fuel needed? Would be length*4=neededFuelForExcavation
New update again. Still a lot to do, like forcing program to hold and wait for fuel if below required. However, that's something I have to do another day, another time.
turtle.select(2)
while not turtle.detectDown() do
turtle.placeDown()
end
Does the exact same thing yours did, but is it performance technical better (which accually doesnt matter because the turtle has allready build-in slowing down commands and animations).
A problem which occurs now is, that if the turtle has no blocks in slot 2 left, it tries to place down a block every tick until it gives a error code at some point ("without yielding" or something crazy). So you can also add a "sleep(0.5)" after the "turtle.placeDown()" which let the turtle wait have a second before checking again.
Howerer, is there not a way for me to let the turtle check if there is any items in slot 2? So that if there are no blocks in slot 2, it goes to slot 3?
However, this should really not be a problem because we are only going to place a one wide bridge to that we can get the turtle if anything happens. And how many 64 block long caves can i find?
Thanks for all your advice on code, you're a really cool coder Love your programs btw
Here is the turtle api, where everything the turtle can do as a turtle.<command> command is listed.
turtle.getItemCount(2) -- gives the amount of items in the slot back
Thank you I started making little programs like you are doing them as well. Some "old" members here in the forums gave me advices and helped me as well, so i try to give everybody a quick start and overview about turtle mechanics and tweaks.
I tried to make the turtle drop off items when done, but it did not work out that great... Maybe you could have a look through it, UNO, and maybe make it work? O.o
To auto-dropoff items, you can place a hopper under the turtle. That hopper can lead down to, say, an ender chest to a sorting system?
I tried to make the turtle drop off items when done, but it did not work out that great... Maybe you could have a look through it, UNO, and maybe make it work? O.o
What ya wanna do? Drop every items in the inventory?
[size=4]for i=1, 16 do[/size]
if turtle.getItemCount(i) > 0 then
turtle.select(i)
turtle.drop()
end
end
Change the 1 for the first slot and the 16 for the last slot to drop.
mymusicmanager, on 23 May 2013 - 02:46 PM, said:
To auto-dropoff items, you can place a hopper under the turtle. That hopper can lead down to, say, an ender chest to a sorting system?
Hoppers arnt part of most fbt versions because they run with MC version < 1.5
I want people to have the option to either make the turtle auto-drop a chest and drop items into that
or to drop items into a pre-placed chest
or just ignore dropping any items
I have tried to declare a local value and reffering to that later on once done mining and moving, but the program did not want to pull the local value, and just ignored all of it.
You created a local chest within multiple if-statements. A local variables just "lives" or "exists" until the next end occurs (simple explanation).
Create the variable at the start of the program and just load it without the "local" if you fill it with information and it should work.
Try to minimize your code a little bit :s
Allways use th for-loop if you allready know what is going to happen. You can put the 32 lines of code in which you drop the whole inventory in the chest into simple 4 lines:
for i=1,16 do
turtle.select(1)
turtle.drop()
end
-- OR a quicker solution while it is running:
for i=1,16 do
if turtle.getItemCount(i) > 0 then
turtle.select(1)
turtle.drop()
end
end
You also should realize that if you are placeing a chest, that you still drop the whole inventory afterwards. You also dont need the Chest variable anymore, so you could re-use this one to shorten your program even more.
if Chest == 1 then -- place the chest
turtle.select(16)
turtle.place()
Chest = 2
end
if Chest == 2 then -- drop the inventory
for i=1,16 do
if turtle.getItemCount(i) then
turtle.select(1)
turtle.drop()
end
end
end
print("Done!")
It is accually bad, that i am showing you the whole code :s
Try to read up about the following commands, because learning it by yourself is much more fun and better.
- for loop
- while loop
- repeat
- functions
- break
- return