41 posts
Posted 28 June 2013 - 10:06 AM
– Original Post:
Hello,
I just wrote my first program. It worked really well, so I thought, I should release it.
I know there are many tree choppers out there, but I only want some feedback.
This is currently unfinished. It'll be full-automatic later.–
No Bonemeal-Version v2:
Spoiler
How to download?
[indent=1]Just type[/indent]
[indent=1]
pastebin get 4uWdzDZp Chopper_nobm
[/indent]
[indent=1]into your turtle/computer. HTTP API must be enabled[/indent]
[indent=1]Fell free to chose the name yourself :D/>[/indent]
The Setup:
Click for bigger pic
You can use a obsidian pipe as output
The code
Feel free to modify it. But try to put my name somewhere :)/>
504 posts
Posted 28 June 2013 - 06:09 PM
Hey there :D/>
it is allways nice to see a new tree chopper ;D There arent as many out there as you may think! :P/>
I looked quickly over the code and found some stuff:
Spoiler
Saplings = tonumber(turtle.getItemCount(16))
if Saplings > 3 then
You dont need tonumber here. You also can put turtle.getItemCount(16) right into the if statement:
if turtle.getItemCount(16) > 3 then
if you are making a yes-no-question i allways would recommand using os.pullEvent(). Look it up in the wiki and understand what it does, because it is very powerful.
In your case i would make it like this:
print("Enable Bonemeal? Y/N")
while true do
local event = {os.pullEvent("char")}
if event[2] == "y" then
bm = true
break
elseif event[2] == "n" then
bm = false
break
else
print("Wrong key!!")
end
end
Also: Just use a function if you need the code more than once or if you want to make it more visual. Last thing is allways by the programmer and coder. However i just recommand using a function, if the code you put into it, has a lot of lines and cover a specific theme or part of your program (e.g. the whole grabbing supplies out of a chest ect,)
Instead of checking every step the turte is doing by putting a checkFuel() behind it, you should a) prefuel the turtle or b)create a function for the movementcommands like this one:
function up()
turtle.up()
checkFuel()
end
This for every movement direction you need or like i said: prefuel.
You also should create local variables at the top/beginning of your program. Just these which you need in your whole script like "bm". You can use it in every function and code in your program.
Just some thingies :P/>Keep on it! Looks great for your first program :D/>
41 posts
Posted 29 June 2013 - 06:56 AM
Thanks for that reply.
I used tonumber(turtle.getItemCount(16)) because without it, it was only a string.
I will use os.pullEvent. Thanks for that. Just didn't know it was there.
And prefueling is a little bit difficult, because the trees aren't at the same size every time. I don't want to create function for every movement I do. At least not in this program.
504 posts
Posted 29 June 2013 - 07:45 AM
turtle.getItemCount() doesnt return a string for me…
If you know the max height of fir trees (around 50) you can go and say, that you need 200 fuel in the turtle before going to chop the next tree. In your case you are checking 79 times for nothing and once out of 80 its returns true and refuels.
Creating functions for movement is allways a good idea, because you can let the turtle handle stuff in its way:
function forward()
while not turtle.forward() do sleep(0.5) end
checkFuel()
end
41 posts
Posted 29 June 2013 - 04:20 PM
I'll think about this. But I'm to lazy to rewrite nerly everything. Going to do that if I'm bored. Also I use checkFuel so often, because it takes the wood blocks to refuel. No addition fuel needed here. I'll post how to set this up when I'm done with it
41 posts
Posted 30 June 2013 - 11:53 AM
Just added another version. This time it's nearly automated.
I'm still working on it
41 posts
Posted 10 July 2013 - 03:28 PM
I updated the no-bonemeal version. The full one should be ready soon.
It's nearly fully rewritten and there's no complex stuff in it. I think this are good conditions if you're new and want to rewrite a program.
I also removed the other version, because it didn't work
504 posts
Posted 10 July 2013 - 03:37 PM
Nice to see you still working on it :D/>