Could you also give an example of how this can be used?
The documentation has a bunch of demonstrations, but without context. Ill make some up here too.
Say you were making a simple AI. The bot will wander around until AIPlayer::OnBotSeeTarget is called, it will then aim at the target and repeatedly fire its weapon, until its dead.
function AIPlayer::CreateTaskManager(%bot) { //Call this when the bot is created
%bot.taskMgr = newTaskManager(%bot);
%bot.taskMgr.selfExecuteTasks(false); //Makes the manager execute the tasks automatically
%bot.taskMgr.addTask("wander(10);", -1, 0, 1000); //Every 1000ms, wander around (actually just calls %bot.wander(10); )
}
function AIPlayer::OnBotSeeTarget(%bot, %target) {
%bot.taskMgr.addTaskFront("fireWeapon();", 10, 1, 200); //Every 200ms, fire weapon, up to 10 times. After that, it will go back to wandering.
%bot.taskMgr.addTaskFront("aimAt(%target);"); //As soon as the bot sees a target, aim at them (assume this is instant) (this will be put before fireWeapon) (this will only be done once)
}
function AIPlayer::OnBotTargetDead(%bot, %target) {
%bot.taskMgr.clearTasks();
%bot.taskMgr.addTask("wander(10);", -1, 0, 1000); //Wander again
}
Yeah that isn't the best example. Its really quite powerful though. Read the top half of the documentation.
How about infinite chunked terrain generation? You want to generate chunks nearest to the player, but want to schedule it out so that it doesnt lag the server. Just make a manager,
%mgr.setDefaultTaskDelay(500); %mgr.selfExecuteTasks(true); and then add chunks to be generated, and every 500ms it will generate the next one on the list.