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

Mining Turtle Program

Started by applesauce10189, 13 December 2013 - 11:32 PM
applesauce10189 #1
Posted 14 December 2013 - 12:32 AM
This program is a big work in progress and will be until I deem it perfection, but it's ready for public use, please give me constructive criticism on what I can do better and/or fix, I'm new to coding and this is my first program meant for public use,

Use: Mining


Requirements: Ender storage mod. For some this might be a bit much to ask for but it's for inventory and refueling. Slot one enderchest is for inventory. The second slot is for the fuel enderchest and I suggest you keep it filled with a fuel source at all times.

Setup: Place the inventory enderchest and place the turtle on top of it before running the program and put the fuel enderchest in the second slot. I know placing the turtle on top of the enderchest is weird but when I first made the program I made it that way for some odd unknown reason. You'll live.

Place torches option: To use the place torches optional function, place a stack of torches in the fourth inventory slot. Future versions of the program may require an enderchest,

Next addition: I plan on making another program to chunk load the mining turtle. Mainly because I plan on making the mining turtle go to bedrock then go up a few blocks then start doing an endless 3x3


It is greatly recommended that you use miscPeripherals for chunk loading with the chunk loader module, I may possibly add a way to do that without MiscPeripherals but that depends on my laziness yet if you have the EnderStorage mod then it's likely you have a modpack and probably have MiscPeripherals


I never would've guessed my program would progress so far, thank you to every one to took the time to read this post and/or comment on it. If I went unnoticed as I thought I would in the beginning I never would've come this far. (lol looking back, this little bit right here makes it look like I did so much and as if I'm so famous or something although all I did was make a simple program.)



get it by typing into a turtle
pastebin get jR019pYK (Name it what you want here,)


ChangeLog (More for me than it is for you, so I can keep track of things I've done/changed with this program)
Spoilerv1 http://pastebin.com/qCf3Lk2r
Changes made: First iteration of the program so there are none to be made.

Features: Just digs a staircase down by 60 Y levels.

Notable bugs: gravel/sand seem to make the turtle to weird things such as go to the side etc. (Bugs aren't fully tested. Just a hypothesis.)

v2 http://pastebin.com/5dr10LL1
Changes made: gravityCheck() function.

Features: Digs down by 60 and gravity blocks don't make it go off course as it used to.

Notable bugs: Seems to skip going backwards for fuel and dropping off items and ends up dropping items on the ground. Cause can be standing in the way but that isn't the only cause. Other causes are unknown.

v3 Woohoo!!!

Changes made: Places torches and digs a 3x3 tunnel.

Features: Optional ability to place torches. You choose how far down it digs. Once it digs however far down you choose it begins a 3x3 tunnel.

Notable bugs: If a player gets in the way of the turtle or a currently unknown cause occurs the turtle may skip going backwards and entirely mess up the program until the tunnel begins.

v3.1

Changes made: No longer randomly messes up entire program. WARNING: can still be caused by a player getting in the way. That bug is ComputerCraft not me.

Features:
Same as v3

Notable bugs: None so far

v3.5

Changes made: Automatically runs pastebin and gets an api I plan to use in the future. Make sure you have no programs named "apple"

Feature: Same as above.

Notable bugs: None so far
Edited on 24 February 2014 - 11:53 AM
applesauce10189 #2
Posted 14 December 2013 - 12:40 AM
The website is doing very weird things to my code can someone help?
Alice #3
Posted 14 December 2013 - 01:02 AM
Post the code to pastebin or put it in a spoiler.
If you put it to pastebin, I'll post the code in the
 tags.
applesauce10189 #4
Posted 14 December 2013 - 01:58 PM
Actually the code was on a server so I needed pastebin just to put it here, here's the link http://pastebin.com/raHRR0Vu
Alice #5
Posted 14 December 2013 - 02:00 PM
Code:
Spoiler

function emptyInventory()
  for i = 2, 16 do
	turtle.select(i)
	turtle.dropDown(64)
  end
end

function appleMine()
  while true do
	for i = 1,60 do
	  turtle.select(1)
	  turtle.digDown()
	  turtle.down()
	  turtle.digDown()
	  turtle.down()
	  turtle.turnRight()
	  turtle.dig()
	  turtle.turnLeft()
	  turtle.turnLeft()
	  turtle.dig()
	  turtle.turnRight()
	  turtle.dig()
	  turtle.forward()
	  turtle.turnRight()
	  turtle.dig()
	  turtle.turnLeft()
	  turtle.turnLeft()
	  turtle.dig()
	  turtle.turnRight()
	  turtle.dig()
	  turtle.forward()
	  turtle.turnRight()
	  turtle.dig()
	  turtle.turnLeft()
	  turtle.turnLeft()
	  turtle.dig()
	  turtle.turnRight()
	  turtle.dig()
	  turtle.forward()
	  turtle.turnRight()
	  turtle.dig()
	  turtle.turnLeft()
	  turtle.turnLeft()
	  turtle.forward()
	  turtle.dig()
	  turtle.turnRight()
	  turtle.back()
	  turtle.back()
	  turtle.up()
	  turtle.placeDown()
	  emptyInventory()
	end
  end
end
turtle.select(1)
appleMine()
Edited on 14 December 2013 - 01:02 PM
applesauce10189 #6
Posted 14 December 2013 - 04:12 PM
Thanks,
applesauce10189 #7
Posted 17 December 2013 - 03:38 PM
:D/> I just made this look a lot more professional than it is. I'm proud of myself lol.
Minion #8
Posted 23 December 2013 - 08:38 PM
:D/> I just made this look a lot more professional than it is. I'm proud of myself lol.

You've got it in an infinite while loop, what's with the For Loop?

A lot of the code just repeats, so why don't you shorten it a bit?

Haven't tested it, but your applefuel() function seems finicky, because if your chest is in that slot… and then you suck something… there's a chance the item might get sucked into the newly vacated (you just placed the chest) slot, and thus ruin any further use of that function lol
applesauce10189 #9
Posted 24 December 2013 - 02:37 AM
:D/> I just made this look a lot more professional than it is. I'm proud of myself lol.

You've got it in an infinite while loop, what's with the For Loop?

A lot of the code just repeats, so why don't you shorten it a bit?

there's a chance the item might get sucked into the newly vacated (you just placed the chest) slot, and thus ruin any further use of that function lol

I'm new to coding, once I get more used to coding and learn a little more I can make it neater/better, and about the applefuel() function, I'm pretty sure it does turtle.refuel() before it actually picks up the chest again, I'm going off memory atm so that may not be 100% correct,
Jim #10
Posted 05 January 2014 - 02:29 AM
You can shorten the code though. As I see, you are using an infinite loop. Just keep the basic turtle steps in the loop and it will execute them from 1 to 60 times. If you want it to be even more, just increase the 60. Also you could use a local variable called times so you can have some kind of question "How many times to execute?" or something. Other than that, good work. Keep trying for the best.
applesauce10189 #11
Posted 05 January 2014 - 10:18 AM
WOOHOO took a long break from coding because I don't know why. But on the upside I just made a v2 of my mining program. As easy or simple many of you think it to be, I'm new to coding so this was somewhat hard to me. I added a function called gravityCheck() which as the name implies, checks for blocks with gravity that have fallen in the way. It has been tested and works. If you go to ask a pro you may find I had a little trouble but I'm new so whatever.
applesauce10189 #12
Posted 07 January 2014 - 05:08 PM
Up until now I've been making this program on the FTB launcher. The FTB Unleashed 1.1.3 mod pack to be exact. Now I'm using the latest Direwolf20 pack. Just a quick heads up.
applesauce10189 #13
Posted 08 January 2014 - 12:15 AM
v3 is out!!!!!!!!!!!!
oeed #14
Posted 08 January 2014 - 02:57 AM
How about adding multiple features to it, so for example, adding a farming module or something?
PEZ #15
Posted 08 January 2014 - 06:18 AM
Thanks for sharing! I like the simplicity of your approach.

I just made my first computercraft script and it's a mining turtle as well. =) Can't post new topics for some reason so spamming your post about it….
applesauce10189 #16
Posted 08 January 2014 - 12:33 PM
Thanks for sharing! I like the simplicity of your approach.

I just made my first computercraft script and it's a mining turtle as well. =) Can't post new topics for some reason so spamming your post about it….
Thanks! This is my first program to have 20+ lines of code needed. None the less 150+. It looks like you're new to the forum, (1 post) just get a couple posts here and there and you can make topics. Also, I don't consider a friendly comment to be spam. :)/>

How about adding multiple features to it, so for example, adding a farming module or something?
I still have a bug or so to get out of this program, but you just gave me an idea, you need separate turtles for separate tasks like farming, mining, tree felling etc, so maybe I could make a program for each of the kinds of turtle, and have one wireless turtle give them commands and such, I'm not ready for wireless stuff but when I am I'm probably going to immediately get started on that!

You can shorten the code though. As I see, you are using an infinite loop. Just keep the basic turtle steps in the loop and it will execute them from 1 to 60 times. If you want it to be even more, just increase the 60. Also you could use a local variable called times so you can have some kind of question "How many times to execute?" or something. Other than that, good work. Keep trying for the best.
Thanks for the idea! In v3 I added that but I never really did read your post, I didn't know you could use variables in a "for" loop at the time.


I just replied to a lot of people……. I feel loved <3
Edited on 08 January 2014 - 11:34 AM
applesauce10189 #17
Posted 08 January 2014 - 01:22 PM
The most annoying bug of all bugs I had to fix is now gone :)/> who would'a guessed in all that repetitive turtle.(move/turn) I'd accidentally type something else on one line?
PEZ #18
Posted 09 January 2014 - 03:32 AM
who would'a guessed in all that repetitive turtle.(move/turn) I'd accidentally type something else on one line?

I would! :)/>

Seriously, all that repetition of the same thing violates the DRY principle - http://en.wikipedia.org/wiki/Don't_repeat_yourself
It opens up for bugs of the sort you just nailed. A first step of drying it up could be to nest another loop and let that one repeat it. Something like so:


function appleMine()
  while true do
    for i = 1,60 do
	  turtle.select(1)
	  turtle.digDown()
	  turtle.down()
	  turtle.digDown()
	  turtle.down()
	  for j=1,4 do
		    turtle.turnRight()
		    turtle.dig()
		    turtle.turnLeft()
		    turtle.turnLeft()
		    turtle.dig()
		    turtle.turnRight()
		    turtle.dig()
		    turtle.forward()
	  end
	  turtle.back()
	  turtle.back()
	  turtle.up()
	  turtle.placeDown()
	  emptyInventory()
    end
  end
end

It also increases the code clarity since the function is shorter and the loop itself tells the reader that "we're doing this thing four times". There are more ways you can increase the clarity of the code, but let's save them for later. :)/>
applesauce10189 #19
Posted 09 January 2014 - 10:57 AM
I'm wondering if I should maybe re-make that part of the code just to improve that, but other than looks of the code I don't see a reason to, maybe if I ever need to make a big change to the program I will, I'm glad I made this program because I mainly made this program to try to get more into coding and such, what kind of program should I make next? Literally taking requests, something somewhat simple, I'm a bit simple, some times more than others :P/>
applesauce10189 #20
Posted 09 January 2014 - 05:30 PM
Just had an idea, I'm gonna work on rednet support so you can use rednet.broadcast() to use a group of turtles instead of just one but quick question, is there a way to use rednet to make a turtle run a command? ex:

rednet.open()
for x = 1, 3 do
id, message = rednet.receive()
os.run(message)
end
Basically what I plan on doing is setting up a bunch of turtles with my mining program so I can type into one computer "pastebin get kh862Y1z" and get applemine on all the computers, then type how far down I want them to go and whether or not to place torches.
CometWolf #21
Posted 09 January 2014 - 05:35 PM
shell.run(message) or loadstring(message)() would do the trick, alternativly you could program it in with if statements depending on what the message is. You will however need the receiver program on the turtle in question. Last time i made a swarm turtle scrip, i had one turtle create and configure all the others. Using a disk drive and a disk you can transfer files to fresh turtles with a startup file on the disk.
applesauce10189 #22
Posted 10 January 2014 - 12:10 AM
Wow, that sounds like chaos, but cool too,
Jim #23
Posted 10 January 2014 - 01:13 PM
Here you go, haven't looked at your updated version, but this is sort of what I meant. Let's say you got the 3 steps **turtle.dig(), turtle.forward(), turtle.digUp()**

local times = 0
print("Hello! How many times to run?: ")
times = read()
  for i = 1, times do
    turtle.dig()
    turtle.forward()
    turtle.digUp()
end
HeffeD #24
Posted 10 January 2014 - 02:43 PM
I'm wondering if I should maybe re-make that part of the code just to improve that, but other than looks of the code I don't see a reason to, maybe if I ever need to make a big change to the program I will, I'm glad I made this program because I mainly made this program to try to get more into coding and such, what kind of program should I make next? Literally taking requests, something somewhat simple, I'm a bit simple, some times more than others :P/>

I would focus on taking other users advice on how to improve the script you have before delving into another project.

Why not make the mistakes only once instead of propagating them through every script you write? Learning to write efficient code will improve any script you write from here on out…
applesauce10189 #25
Posted 10 January 2014 - 05:03 PM
Both Jim and HeffeD, thanks for the advice, Jim I implemented your idea in a recent version, HeffeD I'll get on it right now then,
applesauce10189 #26
Posted 22 January 2014 - 01:38 AM
It's been a while since anything has happened to this post. I just wanted to mention I am now making this on an updated version. Previously I was on FTB Unleashed 1.1.3 now I'm on FTB Unleashed 1.1.7
CometWolf #27
Posted 22 January 2014 - 02:14 AM
Update from unleashed 1.1.3 to 1.1.7 has literally no effect on the CC mod, at all…
applesauce10189 #28
Posted 22 January 2014 - 02:37 AM
Update from unleashed 1.1.3 to 1.1.7 has literally no effect on the CC mod, at all…
Well like I said I just felt like mentioning it. When I said "I am now making this on an updated version" I meant the modpack. Not CC.
CometWolf #29
Posted 22 January 2014 - 02:57 AM
And like i said, it has no effect on cc, and is thus irrelevant to your program or anyone using it.
applesauce10189 #30
Posted 23 January 2014 - 01:05 AM
And like i said, it has no effect on cc, and is thus irrelevant to your program or anyone using it.
Not once have I mentioned it having any possible effect on cc I just wanted to mention I was making my program on an updated version of the modpack I knew it didn't have any possible effect on cc but like I said I just wanted to mention it for the sake of mentioning it.
CometWolf #31
Posted 23 January 2014 - 01:25 AM
The question here is why mention it here… It's the same as me saying "just to mention it, i like pie!" It's irrelevant to this thread…
applesauce10189 #32
Posted 24 February 2014 - 12:42 PM
This program is long overdue for an update, and I was hoping it would be a bigger one than this, but other than code clean up I can't think of anything else that can be done for this program. This change to the program, which could very possibly be the last, is a shell.run that grabs my API from pastebin that I'm working on.