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

At what point is the turtle pos updated?

Started by Qauzzix, 27 February 2013 - 02:18 AM
Qauzzix #1
Posted 27 February 2013 - 03:18 AM
Title: At what point is the turtle pos updated?

The scenario I am thinking about is when the current running coroutine is a turtle code that is about to call a movement function. When the coroutine yields no other coroutines will get execution ( as I understand it ). Is the position and direction of the turtle modified when the turtle code gets execution again or before? I would assume that the movement would never take place if the last running coroutine calls the movement function that will yield until the movement is completed. But assumptions can make bad bugs. At what point during code execution is the turtle location and directions actually updated?
Lyqyd #2
Posted 27 February 2013 - 04:21 AM
Split into new topic.

You can update the position whenever you want; the turtle's location will generally be wherever you told it to be last, except that you might not see the success/failure event come back to let you know whether the move succeeded.
ChunLing #3
Posted 28 February 2013 - 03:49 AM
That is to say, if you are using the turtle functions rather than the turtle.native functions, the turtle is where it is before the movement until the function is called, then the function is running, and then the turtle is where it is after the function.

If you want, you can probably write a version of the turtle movement functions (using the native functions) that uses short timers to "pre-check" if a turtle movement is successful, since false returns on moves are basically instant. If the move doesn't fail, then I believe that the change in position/facing should have been initiated successfully and the turtle is just waiting for the event saying that the animation has finished and the turtle is ready for another move.