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

Accessing raw/native turtle functions

Started by CometWolf, 03 January 2015 - 03:03 PM
CometWolf #1
Posted 03 January 2015 - 04:03 PM
I've recently been getting into minecraft again, and ofcourse along with that, ComputerCraft. As a result i've discovered that a workaround for one of my programs no longer works. Namely using the native turtle functions instead of the wrapped ones, in order to process other events while the the turtle moves. It used to be as simple as

turtle.native.function()
But now this points to the same function as

turtle.function()
which sadly, is the wrapped function. As a result, im unable to get the id for the turtle action, and therefor don't know which turtle_response event corresponds to what action.

Noteably the wrapping of the turtle functions is no longer present in the turtle API, the required events however are still fired. Anyone know if this is a bug, or an intended modification? Or perhaps know of a different way of getting to the raw functions? I realize the parallel API is a probable solution, but it tends to get messy when running in conjuction with other programs and APIs, so i'd like to avoid it if possible. Same goes for global pullEvent overides.
Edited on 03 January 2015 - 03:19 PM
SquidDev #2
Posted 03 January 2015 - 04:22 PM
I think this is intended. TurtleBrain (the class that runs the turtle) looks for a turtle_response event and will not return until it is finished.

The short answer is No. I don't believe there is a way to get to the natives. Though I presume using parallel will work? Maybe?
Lyqyd #3
Posted 03 January 2015 - 05:45 PM
Turtle API functions yield in the Java now. There's no way to call them without yielding and no way to get the ID that the event response will be returning.
CometWolf #4
Posted 03 January 2015 - 06:21 PM
If it's handled java side, would that mean it no longer eats Lua side events? If so, accessing the native functions shouldn't be necessary anyhow.

Edit: Testing shows this to not be the case. Non turtle_response events are dropped from the event queue when a turtle is moving, and overiding pullEventRaw to drop turtle_response events cause the turtle to freeze after a move.
Edited on 03 January 2015 - 05:48 PM
Lyqyd #5
Posted 03 January 2015 - 07:37 PM
It still yields, which means still eating events, it just does it on the Java side, not the Lua side.

I am surprised that modifying pullEventRaw is enough to disrupt it, though. Is pullEvent enough as well, or do you have to use -Raw to get it to start modifying the behavior?
CometWolf #6
Posted 04 January 2015 - 12:20 AM
I haven't tested modifying sans Raw, but i'd assume it would not disrupt it. Earlier while i was trying to debug this issue i modified regular pullEvent to print out the events received. turtle_response was not among them, it was however when Raw was used.
Bomb Bloke #7
Posted 04 January 2015 - 12:41 AM
Indeed, I'm pretty sure turtle functions pull "raw" events, as getting them to respond to Ctrl+T while moving is a painful process.

Assuming the native functions are well and truly outside of your accessible scope, I suppose you could still rig os.pullEventRaw() to pay attention to what sort of event it's being asked for, and if it's a turtle-related event, pile everything else that comes into the queue first into a table. Whenever subsequently asked for an event and there's data in said table, return info from the front of it until empty (possibly pulling and adding one new event onto the end of it for every one that's requested, to ensure it still yields - simply queue a custom event before doing so to ensure there's something to pull).