Jump to content




Mining Program Refueling Efficiency Problem


11 replies to this topic

#1 w1zzard

  • Members
  • 10 posts

Posted 24 October 2013 - 03:28 AM

hi im new to lua and computer craft but ive tried to make my own mining program however i cant seem to get my program to run my refueling code at correct intervals, i tried to use a for loop to run the main code X amount of times and then it refuels but when i ran the program it still ran the refuel code at the same time as my turtle empty code which meant my turtle is still using excessive amounts of charcoal.
also would like some help or hints on how to make the mining size adjustable (its a tunnel mining type) apologies for the newbiness of my program and any help would be appreciated.

it uses 2 ender chests to refuel and empty, empty into my system chest is in slot 15 and the refuel chest full of charcoal is slot 16

link to my most recent pastebin of the program
http://pastebin.com/Zyvh4yHj

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,464 posts

Posted 24 October 2013 - 09:21 AM

Split into new topic.

#3 w1zzard

  • Members
  • 10 posts

Posted 24 October 2013 - 09:32 AM

managed to get my program to follow refueling i wanted, needed some more ends in places, would appreciate if any1 would explain how i could go about changing the size of the tunnel dug with command line variables and if it is possible to make it so the length of the tunnel is specifiable but when nothing is specified it runs for an infinite distance instead of not running?

also wondering if its possible to add in code to make it calculate how often it would need to refuel for one stack of charcoal (this is with the variable height and width added) and set the mining segment of the loop code to that variable.

as always any help appreciated and if u know of any links i can follow to more info that would help

example of how i want it to run:
mine 3 3 10 would mine out a 3x3 tunnel area 10 blocks long
however
mine 9 9 would mine out an endless tunnel 9x9

i know i can do this by adding in variables but ive only picked up lua about a day ago and am having trouble with understanding how i actually go about this

http://pastebin.com/Ua8u5JFL latest pastebin

#4 w1zzard

  • Members
  • 10 posts

Posted 24 October 2013 - 07:03 PM

ok after quite a bit of help from my dad i managed to get this program to work how i wanted it to apart from the fact its going too far on the mining distance, 3 3 2 is mining a 3x3 tunnel 4 blocks long
, i assume this is because the for loop i made isnt halfing the z as i tell it to. how would i go about sorting this?

http://pastebin.com/6cTZgjG4 most recent version of the mining program

#5 25hz

  • Members
  • 14 posts

Posted 25 October 2013 - 03:32 AM

Here is a 3 x 3 miner (http://pastebin.com/dSKfuiNr) and a 1 x 3 miner (http://pastebin.com/VNeaFaDB). Both use a user defined variable called "run". When the script uses the "run" variable to execute the mining loop to the specified distance, it also runs a loop at the bottom of the script to bring the turtle back the same distance.

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 25 October 2013 - 06:47 AM

View Postw1zzard, on 24 October 2013 - 07:03 PM, said:

http://pastebin.com/6cTZgjG4 most recent version of the mining program

Don't use "else do", at least, not that way. You're making two blocks there:

else
  -- I'm inside the "else" block.
  do
    -- I'm inside the "do" block inside the "else" block.
    -- Local variables declared in this "do" block will only exist in this "do" block,
    -- but otherwise it has no point.
  end
  -- "do" block has finished but I'm still in the "else" block.
end

It seems you're thinking the "else" blocks require the "do"s, but they really don't - hopefully understanding this you'll be able to fix your indentation.

Lines 107-135 will never execute because they rely on line 63 evaluating as false and 106 evaluating as true. This is not possible as they both check to see if z==0.

The loop started on line 173 reads "for i = 0 , z/2 do". Every iteration of the loop digs two blocks along the length of the tunnel (one starting at the bottom and digging up, one starting at the top and digging down).

If z is 2 then the loop will go from 0 to 1, hence performing two iterations. Each iteration digs two blocks along the tunnel meaning 4 blocks worth of length.

Using "for i = 1 , z/2 do" is closer to what you want, but still has obvious problems (it won't dig at all unless z starts out at at least 2). You might consider thinking about ditching the division (use "for i=1,z do") and making your loop either tunnel up or down (instead of both) depending on what math.fmod(i,2) currently happens to be.

#7 w1zzard

  • Members
  • 10 posts

Posted 25 October 2013 - 08:53 AM

line 107 should be evaluating from line 64 not 63 being false
its line 171 that should be working from line 63 being false. any help on trying to fix this problem is appreciated

the program basically checks for a length specified then checks for if the y specified is even or odd and runs the appropriate code, or atleast it should do. this is why the first 2 running codes are both saying if z == 0, they are both the infinite distance ones but odd and even height differences.

ty for the for i = 1, z/2 do that is exactly what i want for the program for now, as i said im new to lua, and coding in general.

you said hopefully ill be able to fix my indentation, to do this id need to know how its meant to be.

and to the guy who posted some premade mining programs... not helpful at all, i didnt ask for a premade program i asked for help with the one im attempting to write which is a variable mining program that can be told to dig a 3 x 3 x 20 tunnel or a 100x100x infinite tunnel all in the same program (100x100 would probably need some sort of calculation for the fueling tbh because of how much it would need but tbh i doubt ill use it for more than a 10x10 quarry tunnel type)

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 25 October 2013 - 04:31 PM

View Postw1zzard, on 25 October 2013 - 08:53 AM, said:

line 107 should be evaluating from line 64 not 63 being false
its line 171 that should be working from line 63 being false. any help on trying to fix this problem is appreciated

.
.
.

you said hopefully ill be able to fix my indentation, to do this id need to know how its meant to be.

Let's summarise (and re-indent) lines 63-138:

Spoiler

See how Lua treats things when you use "else do"? This should hopefully allow you to fix the mistake (by moving that "else" in the middle there, and preferably getting rid of those extra "do"s that confused you as to where it should've gone in the first place).

(If I'm still not clear, then the format of your "if" blocks should be if...then...else...end, not if...then...else do...end.)

#9 w1zzard

  • Members
  • 10 posts

Posted 25 October 2013 - 05:27 PM

i tried to go through it and sort the indentation, also tried moving the main bulk of the code into functions so the main program is tiny now

http://pastebin.com/PHdXmJ8j i just need to give it an ingame test to see if this actually runs how i want it to

#10 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 26 October 2013 - 03:17 AM

Delete lines 91, 133, 167 and 200 entirely. Don't try to put anything in their place, just get rid of them. Your script will otherwise crash outright due to overuse of "end" statements.

I'm still not sure if it'll work "correctly" even with that dealt with, though if there isn't anything else gumming the works: Glancing at eg your "limitEven()" and "limitOdd()" functions I see only two lines that differ between the two. You could delete one of the functions, and make use of "if math.fmod(y,2) == 0 then turtle.turnRight() else turtle.turnLeft() end" within the one that's left (as opposed to checking math.fmod(y,2) == 0 to see which function to call). It should be possible to do something similar to get rid of the "inf" functions too.

#11 w1zzard

  • Members
  • 10 posts

Posted 26 October 2013 - 04:12 AM

yeah i ran it through codepad.org and got rid of the excess ends and i do plan on doing ur bit that decides if it needs to go up or down using a for loop where it goes up if odd and down if even (example not sure how ill actually make it run), also ill do your suggested streamlining of the functions after ive got it running how i want first.
after deleting the ends i ran the program and it works fine for the limited distance but running the infinite distance one just doesnt work at all, it grabs charcoal and then stops. i need to track this down and i think its just not going down the infinite route at all and just doing a limited route with a distance of 0 so its not running the program at all basically, gonna add print lines so it says which function its running to see if im right and then gotta figure out why

#12 w1zzard

  • Members
  • 10 posts

Posted 26 October 2013 - 06:33 PM

managed to find out why it wasnt running the infinite distance line of codes.
it checked if z==0, and z = tArgs[3] so ud expect if the third number on ur command line was a 0 it would run that line of code, or atleast that was my logic. however it turns out it was passing the z variable along as a string so it was checking z==0 and the program was saying nope, z = tArgs[3], solved this by making tArgs[3] always dealt with as a number, also added a little more code in that makes sure u have entered 3 variables for width height and length or it wont run, now ive gotta figure out how ill go about sorting the updown part of the code to make it able to mine odd distances.

still need to go through and do your suggested streamlining of the code now ive got the code running as i wanted it to atleast


latest pastebin http://pastebin.com/fre6Sj1n





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users