Jump to content




Mining Turtle Program


31 replies to this topic

#1 applesauce10189

  • Members
  • 162 posts

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)
Spoiler

Edited by applesauce10189, 24 February 2014 - 12:53 PM.


#2 applesauce10189

  • Members
  • 162 posts

Posted 14 December 2013 - 12:40 AM

The website is doing very weird things to my code can someone help?

#3 Alice

  • Members
  • 429 posts
  • LocationBehind you.

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 [code] tags.

#4 applesauce10189

  • Members
  • 162 posts

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

#5 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 14 December 2013 - 02:00 PM

Code:
Spoiler

Edited by Death, 14 December 2013 - 02:02 PM.


#6 applesauce10189

  • Members
  • 162 posts

Posted 14 December 2013 - 04:12 PM

Thanks,

#7 applesauce10189

  • Members
  • 162 posts

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.

#8 Minion

  • Members
  • 8 posts

Posted 23 December 2013 - 08:38 PM

 applesauce10189, on 17 December 2013 - 03:38 PM, said:

: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

#9 applesauce10189

  • Members
  • 162 posts

Posted 24 December 2013 - 02:37 AM

 Minion, on 23 December 2013 - 08:38 PM, said:

 applesauce10189, on 17 December 2013 - 03:38 PM, said:

: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,

#10 Jim

  • Members
  • 33 posts
  • Locationtekkit.craftersland.net:25567

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.

#11 applesauce10189

  • Members
  • 162 posts

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.

#12 applesauce10189

  • Members
  • 162 posts

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.

#13 applesauce10189

  • Members
  • 162 posts

Posted 08 January 2014 - 12:15 AM

v3 is out!!!!!!!!!!!!

#14 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 08 January 2014 - 02:57 AM

How about adding multiple features to it, so for example, adding a farming module or something?

#15 PEZ

  • Members
  • 5 posts

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....

#16 applesauce10189

  • Members
  • 162 posts

Posted 08 January 2014 - 12:33 PM

 PEZ, on 08 January 2014 - 06:18 AM, said:

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. :)

 oeed, on 08 January 2014 - 02:57 AM, said:

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!

 Jim, on 05 January 2014 - 02:29 AM, said:

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 by applesauce10189, 08 January 2014 - 12:34 PM.


#17 applesauce10189

  • Members
  • 162 posts

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?

#18 PEZ

  • Members
  • 5 posts

Posted 09 January 2014 - 03:32 AM

 applesauce10189, on 08 January 2014 - 01:22 PM, said:

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. :)

#19 applesauce10189

  • Members
  • 162 posts

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

#20 applesauce10189

  • Members
  • 162 posts

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users