function atExit(func)
if( type(func) ~= "function" and type(func) ~= "nil" ) then
local err = "Error: Non-function type passed to atExit() where a function is expected.";
setTextColor(cli.yellow);
error(err, 2);
return;
end
local ofunc = __EXIT_CALLBACK
__EXIT_CALLBACK = func;
return ofunc
end
I'm not sure if I agree with this. The default callback just prints a line of text and that's it; there would really be no reason to need to 'chain' it. Rather than setting multiple callbacks in your code, you should combine them into one. You could also just use function hooking to accomplish the same thing.
function exitCallback()
releaseKeys();
end
atExit(exitCallback);
I would like to hook onto it as well in my script but would prefer not to be dependent on the internals of the bot. But its not a biggie, I can call the exitCallback() from my own callback.
Ye, thats what I'm doing atm, problem is that this is a userfunction so what happens if another userfunction also needs to handle the exit or pause callback? Or a user uses it in his/her waypoint script? It would be nice to be able to subscribe to these events without having to hardcode.
Really, that is something that should be handled by the main script. It would be best to register it as an event and have the script call it as the user requests.
What are you attempting to accomplish with the atExit() callback?
I see your point, this prolly should be a task for the executing script.
I've started an Event Manager as an userfunction and will publish in rom userfunction section shortly. It will take over all event exits in MM and enable subscription of these, for compatibility w RoMBot I'm registering all its original callbacks as subscribed on their respective events. The userfunction also enables user defined events for other waypoints/userfunctions to define and subscribe to, as example I'm using player detection and mob detection.
I think that's an excellent idea. When we were working on some scripts for GW2, we had a very clean, event-based system. You might be able to use some of it, or at least get some ideas. https://code.google.com/p/gw2-bot/source/list