Closed rom1504 closed 11 years ago
Not the cutest of code, but you can manually remove the listeners as well.
function stopListeningToNavigator() {
bot.navigate.removeListener('cannotFind', onCannotFind);
bot.navigate.removeListener('pathFound', onPathFound);
}
function onPathFound() {
stopListeningToNavigator();
// your code here
}
function onCannotFind() {
stopListeningToNavigator();
// your code here
}
bot.navigate.on('pathFound', onPathFound);
bot.navigate.on('cannotFind', onCannotFind);
Yes I'm doing that right now, but it's a bit more complicated than this because my onPathFound and onCannotFind function are not always the same. So what i did is store them in global variables, but it's ugly and i'm not sure it cannot have unplanned behaviour (global variables :( )
fixed by 4771e362316864be220e44bf310d5c645915eea2
It would be useful to be able to change those callbacks. Events are not very adapted some time. For exemple i'm doing bot.navigate.once("pathFound", and bot.navigate.once("cannotFind", in my function to get the nearest reachable mob and once any of these events has been caught the listener of the other one should be removed. I'm not sure how to do that and it might be possible, but it would be simpler if i could simply give callbacks to the navigateTo function.