Posted 27 September 2015 - 09: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.
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.