Posted 19 November 2012 - 08:47 AM
Hey there, I stumbled across ComputerCraft today thanks to a friend of mine and started playing around with it. I thought that the native turtle API was quite cumbersome and started implementing some helper functions that ease the general use of ComputerCraft. The code/"API" can be found here: https://gist.github.com/4107076. If there are questions regarding the code ask them and I'll try my best to answer them.
My code implements the following:
My code implements the following:
- _set_default_table_value(table, default): Allows to change a Lua table's metatable quickly so that "default"-values can be set
- get_input(prompt): Just a more comfortable way to get certain user input.
- rotate(degrees): Degrees can be positive and negative, 90° will cause the turtle to turn right, -90° left etc.
- _on_move_fail(direction, move): Callback used by the move function. If your version of this callback does not return true the move function returns.
- _on_move_success(direction, move): Callback used by the move function.
- move(direction, blocks, on_success, on_fail): Allows the turtle to move forward, back, up, down, left and right – For left and right the orientation is automatically adjusted. For each traversed block the on_success callback (defaults to _on_move_success) is called, in case the turtle can't traverse a block the on_fail callback (defaults to _on_move_fail) is called.
- _on_dig_fail(direction, dug): Callback used by the dig function. If your version of this callback returns true the move function returns.
- _on_dig_success(direction, dug): Callback used by the dig function.
- dig(direction, blocks, move_to_last_block, on_success, on_fail): Allows the turtle to dig forward, back, up, down, left and right – For left and right the orientation is automatically adjusted. For each dug block the on_success callback (defaults to _on_dig_success) is called, in case the turtle can't dig a block the on_fail callback (defaults to _on_dig_fail) is called. move_to_last_block defaults to false and if set to true will cause the turtle to not only dig the last block in the given direction but also move to it afterwards.
- refuel(slot, quantity): Uses an item in the given slot and refuels itself with the given quantity.