Hey guys! Just wanted to show off something I recently started working on around making turtles a little bit smarter.
Essentially what I'm trying to do is make turtles a little more fail proof as well as make things easier.
Unfortunately, I'm not sure that anything can be done to handle chunk unloads... the turtle's simply not aware of chunk unloads. VikeStep had a good idea about saving turtle state and resuming on startup, but after further investigation I just don't think this is feasible (at least not with my limited knowledge of Lua). It looks as if the Lua debug library would be helpful here, but the developers of CC have purposefully omitted this from ComputerCraft as it is extremely dangerous.
An important note is that this will be a startup script (or a script you can call from an existing startup script, if you have one) which will overwrite the existing turtle API meaning everything will be accessible directly off of the turtle API without having to include anything special in your programs. Any existing code will automatically be updated to use the new API as well. Not to fear, though, as everything I've created so far is backwards compatible. If there's anything I can't make backwards compatible, it will get a name that does not clash with the turtle API.
Thoughts?
Essentially what I'm trying to do is make turtles a little more fail proof as well as make things easier.
- There are situations where a mob (or player or animal or whatever) might walk into the path of your turtle and most people don't check for failure on forward, up, back, or down. My updated turtle API will automatically retry if the turtle fails to move. If a max # of retries is hit, the turtle will pause the script and wait for you to tell it to resume... it will then continue where it left off as if nothing happened.
- The ability to pass a number into your movement options (up/down/back/forward) in order to move a certain # of blocks without having to write your own loop.
- The ability to pass a function in to your movement commands in order to perform an extra set of code for each step your turtle makes (ex: turtle.forward(10, functionThatPlantsASeedAtEveryStepGoesHere))
- Falling blocks (sand, gravel) can often interfere with a turtle's script (again, if you don't account for it). The updated turtle API that I'm building will always check for falling blocks when digging in an attempt to avoid unexpected behaviour.
- New movement options:
- turtle.right(num, reorientOnEachStep, functionPerStep)
- Move to the right a certain number of blocks without having to call turtle.turnRight() followed by several turtle.forward()s
- reorientOnEachStep (true/false) will make the turtle turn left after each step in case your function requires the turtle to be facing the original direction (ex: putting a bunch of signs up on walls, maybe?)
- turtle.left(num, reorientOnEachStep, functionPerStep)
- Same as turtle.right... but to go left
- turtle.rectangle(path, width, length, functionPerStep)
- The turtle will follow a predefined (or maybe even custom) rectangular path (such as backAndForthRows, shrinkingPerimeter, or onlyPerimeter)
- The rectangle that the turtle follows this path within will be sized to the width and length provided
- As with other movement functions, the turtle will perform a function at each step
- Use this to fill in an area with blocks or dig blocks out, etc
- Never have to write custom code to move your turtle in a rectangular pattern again!
- turtle.box(path, width, length, height, functionPerStep)
- As with turtle.rectangle, but add height!
- Allows the turtle to perform a series of functions within a predefined box area! (ex: build a boxtacular house!)
- Never have to write custom code to move your turtle in a box pattern again!
- turtle.right(num, reorientOnEachStep, functionPerStep)
- Automatic refueling
- I hope (but am not promising) to also have the turtle be able to remember any charge stations it might come across. This would be handy if you have a turtle performing some task within a predefined area... no need to check if the turtle runs out of fuel... it will take care of itself.
- Internal GPS (no promises on this one)
- After an initial calibration (each time you put down the turtle) - either manual or through an existing GPS - the turtle will track its own location
Unfortunately, I'm not sure that anything can be done to handle chunk unloads... the turtle's simply not aware of chunk unloads. VikeStep had a good idea about saving turtle state and resuming on startup, but after further investigation I just don't think this is feasible (at least not with my limited knowledge of Lua). It looks as if the Lua debug library would be helpful here, but the developers of CC have purposefully omitted this from ComputerCraft as it is extremely dangerous.
An important note is that this will be a startup script (or a script you can call from an existing startup script, if you have one) which will overwrite the existing turtle API meaning everything will be accessible directly off of the turtle API without having to include anything special in your programs. Any existing code will automatically be updated to use the new API as well. Not to fear, though, as everything I've created so far is backwards compatible. If there's anything I can't make backwards compatible, it will get a name that does not clash with the turtle API.
Thoughts?