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

Miner Program

Started by Lemur, 08 September 2014 - 02:14 AM
Lemur #1
Posted 08 September 2014 - 04:14 AM
Fairly straightforward miner program. Fills in empty blocks below the path and lays torches every 5 blocks if you tell it to. First program on here. Any thoughts? The fuel level needs to be reworked a bit, but other than that it works.

http://pastebin.com/73gH7BUL
civilwargeeky #2
Posted 09 September 2014 - 04:38 AM
Hi! I tried out your program and it worked very well. Did exactly what I expected. Good job :)/>

A little bit of polish and a suggestion though.
I think it would be faster if instead of turning around to place torches, you just use turtle.placeUp(). This way it is about a second quicker anytime it wants to place a torch.
Also, if you take the time to learn how they work, it is much better to use local variables so you don't "pollute the global namespace", but that is a bit advanced so probably don't worry about it yet.
Finally maybe prompt the user for a distance if they didn't input one instead of just using a default. Or maybe just print the help if you have no arguments.

Also a suggestion, you mentioned you would work on the fueling section of your program. If you wanted to take a tip (or use it verbatim, I don't care), you could look at a simplified and commented writing of how I handle getting fuel
That's about it. If you have any questions or need help you can feel free to ask me.

Also I love the quote in your signature :)/>
Lemur #3
Posted 09 September 2014 - 07:39 AM
Hi! I tried out your program and it worked very well. Did exactly what I expected. Good job :)/>/> A little bit of polish and a suggestion though. I think it would be faster if instead of turning around to place torches, you just use turtle.placeUp(). This way it is about a second quicker anytime it wants to place a torch. Also, if you take the time to learn how they work, it is much better to use local variables so you don't "pollute the global namespace", but that is a bit advanced so probably don't worry about it yet. Finally maybe prompt the user for a distance if they didn't input one instead of just using a default. Or maybe just print the help if you have no arguments. Also a suggestion, you mentioned you would work on the fueling section of your program. If you wanted to take a tip (or use it verbatim, I don't care), you could look at a simplified and commented writing of how I handle getting fuel That's about it. If you have any questions or need help you can feel free to ask me. Also I love the quote in your signature :)/>/>

As of right now I'm just haphazardly screwing around in Lua. That program was maybe after a few minutes of screwing about the APIs and guessing how things worked.

On reference, I'm a Software Engineer professionally so advanced won't scare me much at all. Again, this was far more of a get it to work thing than anything. I probably just forgot to tag variables with local more than anything else. Any quick rules of thumb on that?

I was rather put off when map and reduce functions wouldn't work though.
Bomb Bloke #4
Posted 09 September 2014 - 11:45 AM
I probably just forgot to tag variables with local more than anything else. Any quick rules of thumb on that?

The "quick rule of thumb" is "localise everything". If you don't need it to remain loaded in RAM once your script ends, then it at the very least it should be declared as local to that script. Personally I like to pre-declare all variables at the beginning of the scope in which I wish to use them.

It's worth noting that turtle.detect() doesn't pick up on mobs, and turtle.dig() doesn't harm them, either. A turtle with a tool has access to turtle.attack(), though, meaning you can use code along these lines:

while not t.forward() do
  turtle.dig()
  turtle.attack()
  sleep(0.8)  -- The time it takes for sand/gravel to fall.
end

Generally, it's a good idea to pay attention to whether a given movement was successful or not, rather than trying to rig up a circumstance where it "should" work then not bothering to check whether it did. Turns are relatively reliable, but even those can fail under certain obscure circumstances.
Lemur #5
Posted 10 September 2014 - 02:34 AM
I probably just forgot to tag variables with local more than anything else. Any quick rules of thumb on that?

The "quick rule of thumb" is "localise everything". If you don't need it to remain loaded in RAM once your script ends, then it at the very least it should be declared as local to that script. Personally I like to pre-declare all variables at the beginning of the scope in which I wish to use them.

It's worth noting that turtle.detect() doesn't pick up on mobs, and turtle.dig() doesn't harm them, either. A turtle with a tool has access to turtle.attack(), though, meaning you can use code along these lines:

while not t.forward() do
  turtle.dig()
  turtle.attack()
  sleep(0.8)  -- The time it takes for sand/gravel to fall.
end

Generally, it's a good idea to pay attention to whether a given movement was successful or not, rather than trying to rig up a circumstance where it "should" work then not bothering to check whether it did. Turns are relatively reliable, but even those can fail under certain obscure circumstances.

Yeah, I noticed that with gravel being a pain with lag on the server.