Jump to content




Turtle movement timing


3 replies to this topic

#1 negamartin

  • Members
  • 46 posts

Posted 27 September 2015 - 08:59 PM

Turtle's movement and turning functions work weird. I think they changed it in one update. I was surprised to not find this anywhere, so I will leave it here for future reference.

Before, turtle functions worked this way:
turtle.forward (a lua function) calls turtle.native.forward (a native, java function), which returns an activity ID. Then turtle.forward yields for a special event wit that ID, and later returned. This allowed for asynchronous calling of the turtle API by using turtle.native.x functions. This meant turtle.forward (and any other movement function) returned when the move finished.

Instead, now it works this way:
Calling turtle.forward just calls turtle.native.forward, and then returns. turtle.native.forward waits for the turtle to finish its previous move, and then returns, without waiting for the current move to finish. This means that calling turtle.forward will return almost immediately (it does yield for a small time always), so it can continue with the rest of the code. However, when you chain turtle instructions (Eg: turtle.forward()turtle.forward()) the second turtle.forward will wait for the previous move to finish before doing the next move. To do asynchronous calling you have to use the parallel api or a coroutine manager to do stuff while java yields.

That's it. Please note that I haven't decompiled the CC's source or anything, I just think it works this way from the tests I've done (I'm pretty sure it works this way)
If you have some additional information, or maybe my information is wrong (very possible) just tell me so I can edit it.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 27 September 2015 - 11:47 PM

I guess you could say that the change boils down to the "turtle_response" events being generated when the action starts, as opposed to the old behaviour, where they were generated when the action ended. Everything else seems the same.

#3 negamartin

  • Members
  • 46 posts

Posted 28 September 2015 - 10:42 AM

Yes, but there is one more change: turtle.native.x functions do the same, they wait too.
Are you sure "turtle_response" events are still being fired? I didn't really check.
EDIT: Oh, and everything seems to bug out if you abuse turtle.native

Edited by negamartin, 28 September 2015 - 10:44 AM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 28 September 2015 - 11:51 AM

Yes, "turtle_response" events are still a thing.

The turtle.native table, in current ComputerCraft builds at least, contains the same function pointers as you'll find in the regular turtle table. We no longer have access to the "real" turtle.native functions, the ones which run in async, at all.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users