Jump to content




Very simple mining program - Newbies will love this


  • You cannot reply to this topic
21 replies to this topic

#1 mymusicmanager

  • Members
  • 18 posts

Posted 21 May 2013 - 09:24 AM

Hello everyone!

First post here, so I'm a little excited..


Okay, this is a VERY simple and basic mining program. It can't go wrong :P

http://pastebin.com/9WuGM99n


Code:
Spoiler



Basic idea is: You start the program :P

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


Thanks A LOT to UNOBTANIUM for helping me so much with this code :)


WOA! 500 views in under a week? You guyes are awsome!

#2 unobtanium

  • Members
  • 505 posts

Posted 21 May 2013 - 10:10 AM

Hello there,

sweet little program you created there. I went over the code quickly and found some parts you might want to improve ;D

Spoiler


#3 mymusicmanager

  • Members
  • 18 posts

Posted 21 May 2013 - 10:41 AM

View PostUNOBTANIUM, on 21 May 2013 - 10:10 AM, said:

Hello there,

sweet little program you created there. I went over the code quickly and found some parts you might want to improve ;D

Spoiler


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

Thanks for the feedback :)

#4 mymusicmanager

  • Members
  • 18 posts

Posted 21 May 2013 - 11:20 AM

Okay, Minor tweaks and small changes. Will now handle sand and gravel, even if it falls on top of the turtle

#5 mymusicmanager

  • Members
  • 18 posts

Posted 21 May 2013 - 12:41 PM

New update :P

Hopefully fixed the refueling issue

#6 unobtanium

  • Members
  • 505 posts

Posted 21 May 2013 - 01:04 PM

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

#7 mymusicmanager

  • Members
  • 18 posts

Posted 21 May 2013 - 01:24 PM

Let me experiment a bit with that, and see what I come up with

#8 mymusicmanager

  • Members
  • 18 posts

Posted 21 May 2013 - 02:17 PM

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.

#9 unobtanium

  • Members
  • 505 posts

Posted 21 May 2013 - 02:35 PM

I would add a while loop on line 29 to solve your refuel problem

if param1 == "y" then
turtle.select(1)
while turtle.getFuelLevel() < FuelNeeded do
turtle.refuel(1)
end
else


#10 mymusicmanager

  • Members
  • 18 posts

Posted 22 May 2013 - 07:52 AM

I was wondering, If I did something like this during the mining program:

local CheckDown = turtle.detectDown()


while CheckDown = false do
turtle.select(2)
turtle.placeDown()
end


or should I do

local CheckDown = turtle.checkDown()
while not CheckDown do
turtle.select(2)
turtle.placeDown()
end

This is to make a bridge if required. Slot 2 should be filled with cobblestone, of course

Which of thse would work for the best?

#11 unobtanium

  • Members
  • 505 posts

Posted 22 May 2013 - 10:28 AM

It would be like this:
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.

#12 mymusicmanager

  • Members
  • 18 posts

Posted 22 May 2013 - 12:45 PM

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? :P

Thanks for all your advice on code, you're a really cool coder :) Love your programs btw

#13 unobtanium

  • Members
  • 505 posts

Posted 22 May 2013 - 01:06 PM

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

#14 mymusicmanager

  • Members
  • 18 posts

Posted 23 May 2013 - 02:46 PM

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? :P

#15 unobtanium

  • Members
  • 505 posts

Posted 23 May 2013 - 03:12 PM

View Postmymusicmanager, on 23 May 2013 - 02:46 PM, said:

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.

View Postmymusicmanager, 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? :P
Hoppers arnt part of most fbt versions because they run with MC version < 1.5

#16 mymusicmanager

  • Members
  • 18 posts

Posted 24 May 2013 - 03:57 AM

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.

#17 unobtanium

  • Members
  • 505 posts

Posted 24 May 2013 - 05:13 AM

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

#18 mymusicmanager

  • Members
  • 18 posts

Posted 24 May 2013 - 08:57 AM

Thanks, will do ;)

#19 mymusicmanager

  • Members
  • 18 posts

Posted 24 May 2013 - 12:13 PM

Okay, cleared up a lot of code, and everything works perfectly. Still doing research on CC commands, and might include more features in the future

#20 mymusicmanager

  • Members
  • 18 posts

Posted 26 May 2013 - 07:04 PM

Turtle should not need any changes in the code for the 1.5.2 update. I hope 1.6 don't change too much stuff in code...

Anyway, few more imporvements. Also, thanks for over 1000 views :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users