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

Troubles with persistence

Started by Cycomantis, 15 February 2014 - 06:16 AM
Cycomantis #1
Posted 15 February 2014 - 07:16 AM
I'm using the following bit of code to track my turtles movements when it is mining. Sometimes when he is unloaded and then reloaded and starts back up he will have moved but his coordinates did not get updated. Is there a better way to do it?


function up( steps )
local steps = steps or 1
for x = 1, steps do
  tCoords["y"] = tCoords["y"] + 1
  savePos()  --just a function that serialize the table and save it to a file
  while not turtle.up() do
    turtle.digUp()
    turtle.attackUp()
    sleep(.1)
  end
end
end
Molinko #2
Posted 15 February 2014 - 03:11 PM
whenever a Turtle is moving in multiplayer at the server shutdown there is as chance that the turtle can finish a turtle.native call and exit the current function before you can check the result of the call and save accordingly.. there its an API called "Lama" on the forums which uses fuel calculation and custom startup scripts fir each call to a call that changes the turtle position. It can be a bit taxing on execution time. With that said, its a very clever solution.
Cycomantis #3
Posted 15 February 2014 - 04:34 PM
Thank you I will take a look at Lama and see if I can implement something similar.
Bomb Bloke #4
Posted 15 February 2014 - 07:00 PM
My preferred method is to use the GPS API to get the turtle's location on boot, rather then loading it from a file. This has the advantage of removing all need to write it to the drive at all, though depending on the sort of tasks the turtle performs, you may still need to record eg which way it was going etc.
Cycomantis #5
Posted 16 February 2014 - 01:19 AM
My preferred method is to use the GPS API to get the turtle's location on boot, rather then loading it from a file. This has the advantage of removing all need to write it to the drive at all, though depending on the sort of tasks the turtle performs, you may still need to record eg which way it was going etc.

I have been debating on doing that exact thing, but maybe more as a verification tool then for the entire movement tracking.

The turns and direction he is facing is something that I'm having issues with as well. It sucks when he turns and mines over an area he has already mined due to not counting the turns correctly. Do you have any tips other then doing the update prior to the physical move? Right now I'm testing that method and it seems to be working for the most part.