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

Sugar Cane Farm - SUGARGEN

Started by stubob, 14 March 2015 - 06:59 PM
stubob #1
Posted 14 March 2015 - 07:59 PM
Hello!
This is my second ComputerCraft script.




SIDE VIEW
T = Turtle
C = Chest
◘ = Sugarcane

T
C◘◘◘◘◘◘◘◘◘◘◘◘◘◘◘
▬▬▬▬▬▬▬▬▬





Link:
http://pastebin.com/U84r7yaX

Cmd:
pastebin get U84r7yaX caneFarm


todo:
Refuel
persistence?

Give me any feedback / ideas for improvement.

ENJOY!
jerimo #2
Posted 15 March 2015 - 02:31 AM
Well hello again!

Just a few thoughts on methodology, you could have your turtle do turtle.inspect() which returns tue name of the bloxk, such as "minecraft:sugarcane" i believe, to see if its sugarcan and add to a variable to know how far it went and return to start, that way it can be any length
stubob #3
Posted 16 March 2015 - 04:11 PM
Hello Jerimo!

The length and width is configurable in the code - (I do think that I would like to make these arguments that you can pass in). Checking the block's name wouldn't work because there can be empty space over the farm (when the sugar hasn't grown yet), which is worst case. I guess that I could make a special brick that it checks for, and you could set that up as a boundary, but I don't think that I will do that.

I am having a problem with the turtle moving however. If someone is in the way, or if it is unable to move, it will skip that step and get off of the track. What is the best way to ensure that my turtle has moved after I tell it to move? Anyone have a suggested solution for a problem like that? (line 33 in the code)
KingofGamesYami #4
Posted 17 March 2015 - 12:33 AM
I am having a problem with the turtle moving however. If someone is in the way, or if it is unable to move, it will skip that step and get off of the track. What is the best way to ensure that my turtle has moved after I tell it to move? Anyone have a suggested solution for a problem like that? (line 33 in the code)

Turtle movement return true/false based on whether or not they were successful.


while not turtle.forward() do --#try to move forward, if not
  turtle.attack() --#try to attack
  turtle.dig() --#try to dig
end --#repeat
jerimo #5
Posted 17 March 2015 - 04:26 AM
Hello Jerimo!

The length and width is configurable in the code - (I do think that I would like to make these arguments that you can pass in). Checking the block's name wouldn't work because there can be empty space over the farm (when the sugar hasn't grown yet), which is worst case. I guess that I could make a special brick that it checks for, and you could set that up as a boundary, but I don't think that I will do that.

I am having a problem with the turtle moving however. If someone is in the way, or if it is unable to move, it will skip that step and get off of the track. What is the best way to ensure that my turtle has moved after I tell it to move? Anyone have a suggested solution for a problem like that? (line 33 in the code)
Right, forgot the down in inspectDown, that way it checks if its sugarcane under it, which it would only have to do once really, then if it gets stopped short something is in the way and you can collect the sugarcane if not there SHOULD be a sugarcane under the next block fr which you can check
Edited on 17 March 2015 - 03:27 AM
stubob #6
Posted 17 March 2015 - 10:16 PM
ah that would be good.
The Lone Wolfling #7
Posted 18 March 2015 - 11:49 AM
A suggestion regarding persistence.

This is the sort of program that can use "fake" persistence. In other words, you don't need to explicitly store position across restarts. Which is good, because currently there is no way to reliably do so.

What you do is box the turtle in (by, say, a ring of blocks at two high. If you don't want to block movement you can use signs or something.). Then, on startup, just have the turtle move forward and inspect until it hits the blocktype the ring is made of. Check to see if the chest is below the turtle, turn right (or left), and repeat until you see the chest. This will get you back to your starting point.

Alternatively, move the chest up one block, and just make it so the turtle always stays above sugar cane. (It will slow down growth slightly, as it blocks one sugar cane from growing, but not too much.) (Note: you cannot actually make it so the turtle always stays above sugar cane without additional blocker blocks. However, what you do is, if you are above sugar cane never move backwards. Then, if you aren't above sugar cane, move back one and you should be above sugar cane again.)
Edited on 18 March 2015 - 10:49 AM
stubob #8
Posted 04 April 2015 - 11:41 PM
Lone Wolf, I think that that would be a good idea. Thanks for the suggestion! :)/>