Posted 04 December 2012 - 02:03 AM
Hey,
as im writing a little program for my turtle (eg movement via keys, autorespond to some server request,…) i was trying to not use any multithreading or coroutines, but to use only os.pullEvent and some marker, like:
It all went well until I tried to use the TurtleAPI, turns out there's a function (local waitForResponse()), that discards all events other than the one it needs, that, of course, screws my design pretty good, since my "last_event" is just discarded too and the whileloop wont stop pulling events.
Sugestion 1:
So how about changing waitForResponse to something like what i do in my program, queuing some kind of marker, pulling all events up to that marker and requeue all events not used by waitForResponse, if still waiting for some special event, then either do it all over again or just put all events in some sort of table and requeue it after all events needed have been dealt with.
Sugestion 2:
How about a timeout for os.pullEvent() so if it returns false after a period of time I know there is no event without using some kind of marker and still being able to do something else other than waiting for events to happen.
PS: If anyone knows where to find the actual turtle-api-file on my pc, please let me know so i can test it
as im writing a little program for my turtle (eg movement via keys, autorespond to some server request,…) i was trying to not use any multithreading or coroutines, but to use only os.pullEvent and some marker, like:
--mainloop
os.queueEvent("last_event")
while runCheckLoop do
local event, param1, param2, param3 = os.pullEvent()
if event == "last_event" then
runCheckLoop = false
--other events
end
end
--other code
It all went well until I tried to use the TurtleAPI, turns out there's a function (local waitForResponse()), that discards all events other than the one it needs, that, of course, screws my design pretty good, since my "last_event" is just discarded too and the whileloop wont stop pulling events.
Sugestion 1:
So how about changing waitForResponse to something like what i do in my program, queuing some kind of marker, pulling all events up to that marker and requeue all events not used by waitForResponse, if still waiting for some special event, then either do it all over again or just put all events in some sort of table and requeue it after all events needed have been dealt with.
Sugestion 2:
How about a timeout for os.pullEvent() so if it returns false after a period of time I know there is no event without using some kind of marker and still being able to do something else other than waiting for events to happen.
PS: If anyone knows where to find the actual turtle-api-file on my pc, please let me know so i can test it