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

Simple Movement and Item Management

Started by mikebald, 10 January 2013 - 07:01 AM
mikebald #1
Posted 10 January 2013 - 08:01 AM
Worked on a couple APIs that have simplified some of my other turtle scripts. As the title implies, they are simple APIs so they leave out a bunch of the checking that should probably be in place.

util_move http://pastebin.com/9ztmF89F :
The axis I chose was a forward, right, down axis from the initial orientation of the turtle. Each of the movement functions updates the turtle's location on a stored grid [position] so using Forward and MoveTo interchangably is acceptable. As a note, Forward, Up and Down move the amount provided or 1 space if no parameter is provided.

functions:
  • TurnTo ( direction ) – accepts "forward", "right", "back", "left"
  • Forward ( amount ) – moves in the direction it's facing with digging and attacking
  • MoveTo ( forward, right, down ) – moves to a specific position on the grid [0, 0, 0 is start]
  • TurnAround() – flips the direction of the turtle
  • Up ( amount ) – moves up with digging and attacking
  • Down ( amount ) – moves down with diging and attacking
util_item http://pastebin.com/yPwTNewj
I wanted to make item selection, checking and placing easier along with refueling.

functions:
  • DropAll() – drops all the items from the turtle
  • MoveAll( from, to ) – moves all items from 1 slot to another
  • FuelNeeded ( moves ) – displays the Fuel needed for the suspected # of moves. Pretty sure the math is wrong here.
  • Refuel ( slot ) – uses up all the fuel in the given slot
  • RefuelAll() – tries to refuel using the entire turtle inventory
  • NonEmptySlot() – gets the next available slot that is not empty
  • PlaceNext() – places the next available block down, if it can't it digs or attacks what is ever in the way
  • ConfirmFull() – returns true is the turtle is fuel, false if not. It checks against the maximum stack size, not comparing to 64
  • ConfirmAmount( amount ) – returns true if the amount of items on the turtle meets or exceeds the given amount, false if not.
Eric #2
Posted 10 January 2013 - 10:54 AM
When I did this, I replaced the builtin turtle api members with my position-tracking ones. As a result, the turtle continues to track its position even when you run a builtin program like `go`.
mikebald #3
Posted 11 January 2013 - 05:43 AM
Wow, I wouldn't even have considered a move like that [no pun intended]. Thanks Eric I'll have to give that a try once I polish it off much more.
Eric #4
Posted 11 January 2013 - 09:00 AM
Wow, I wouldn't even have considered a move like that [no pun intended]. Thanks Eric I'll have to give that a try once I polish it off much more.
While I make no claim that mine is better, you might want to check out the source code for comparison - I supect you'll be surprised by the way I wroite it:

Main file: https://github.com/eric-wieser/cc-scripts/blob/master/apis/turtletracker.lua
`direction` api: https://github.com/eric-wieser/cc-scripts/blob/master/apis/direction.lua

Looks like I forgot to commit the newest version (with moveTo, etc), but the missing part are not significantly different to your implementation. - Fixed. I'd forgotten how clever I'd tried to be when writing that.
Edited on 11 January 2013 - 08:13 AM