Load and Unload.js - GodDragoner/TeaseAIJava GitHub Wiki
Load- and unload.js
You can use two files named load.js and unload.js in the root of your personality to execute code when the personality is selected/deselected in TAJ. They work the same way as the main.js file so you can just start putting code in them. However any function or variable loaded will not be accessible in the later run of the main.js file which means you have to load it again. For example if your load.js file contains a function called sendMyMessage() you cannot access this method from the main.js file or any other file (after the personality started) unless you run the load.js file manually again. This is because the load and start process are two different ones and do not share anything. However you can use the load.js to setup variables or other stuff. For example you can register your supported variables using that file:
registerVariable("anallimit", "Anal Limit", "Is anal a hard limit, allowed, needs to be addressed or still a matter of discussion?");
This will register the variable anallimit as supported before the personality was even started and now the gui will display this variable correctly with its description and custom name even if the user hasn't run the personality yet. Another use case for the load.js file would be to pre-set variables. You could just use setVar("x", 1) or whatever in the load.js file. You don't need to unregister anything in the unload.js file however if you want to run code when the personality is deselected use it.