86 posts
Posted 17 July 2015 - 02:33 AM
I seem to recall reading somewhere that it is possible to call the turtle move forward command directly without the abstraction provided by the turtle.forward() api. Since this api causes all rednet messages to be dropped while running i would like to manaully run it including starting the timer and waiting for the event.
My code structure is along the lines of
while
ospulleventraw
if event is a then
elseif event is b then
end
end
obviously that isn't code. if anyone has the full turtle.forward() code that would be awesome as i could allow for everything it does without the local yield.
Also i want to update the movement tracker and transmit the movement as soon as it happens and not after the full movement to avoid desync from crashes and chunk unloads etc.
8543 posts
Posted 17 July 2015 - 02:49 AM
The native turtle functions are no longer available in current versions of ComputerCraft. The best way is to use a second coroutine running in parallel with your turtle control routine that will handle all communications.
86 posts
Posted 17 July 2015 - 02:54 AM
Bleh, thanks.
Okay as a follow up, if i call a coroutine that will make the turtle move forward, it will immediately yield back to the main thread so using coroutine.yield() to report tht the move has finished or failed or anything seems like it would not work reliably. How would you suggest to monitor if the action has been successful and when it has completed?
Edited on 17 July 2015 - 01:09 AM
8543 posts
Posted 17 July 2015 - 03:33 AM
Declare a table before the coroutines are started. Have the turtle movement coroutine add things to the table indicating success/failure and have the other coroutine watch that table to see the progress.
7083 posts
Location
Tasmania (AU)
Posted 17 July 2015 - 04:20 AM
Or, perhaps, have the other coroutine watch for turtle_response events.
86 posts
Posted 17 July 2015 - 02:42 PM
That makes a lot more sense, than tables.
I was thinking once the coroutine yields it will not update the table until it is called again which would defeat the whole point.
86 posts
Posted 17 July 2015 - 03:30 PM
os.pullEventlRaw() does not return anything on completion of a move.
Edited on 17 July 2015 - 01:50 PM
656 posts
Posted 17 July 2015 - 04:17 PM
os.pullEventlRaw() does not return anything on completion of a move.
It will when you run it in another coroutine.
8543 posts
Posted 17 July 2015 - 04:33 PM
Or, perhaps, have the other coroutine watch for turtle_response events.
Sure, that'd tell you whether or not the last command succeeded, but it won't tell you anything about what that last command was. They are both viable options, depending on one's needs.