Skip to content

Coding FAQ

GodDragoner edited this page Apr 9, 2018 · 22 revisions

How do I run/execute another file?

Use the run method for this. Example:

run("Modules\Tease\first.js")

The path is always based on your main personality directory. Which means the absolute/resulting path for this would look something like this: D:\Programs\Java AI\Personalities\YourPersonalityFolderName\Modules\Tease\first.js

You can also use the native load method of java nashorn, however the path now refers to the main directory of the tease ai java installation which means the code would look something like this:

run("Personalities\YourPersonalityFolderName\Modules\Tease\first.js")

I do not recommend this method because whenever your personality folder name changes (for example if you change the version and append it to the name: "Example Personality 1.1") it will break.


How do I send a message to the sub and directly execute the following code?

By default the program adds a delay after each message before continuing that is based on the length of the message so the sub has the time to read it. If you want to skip this delay just use:

sendMessage("Your message", 0);

This will send the message and sets the delay to 0 seconds, which means it will automatically continue with the following code. This can be used to executed directly afterwards/kinda "simultaneously" or send rapid messages.


How would I wait for the sub to be on the edge?

Code example:

//Start by sending the message and IMMEDIATELY executing the code afterwards (thats why the 0 is there)
sendMessage("Edge!", 0);
startStroking(250);
startEdge();

//Now we will check whether the sub is on the egde every 100 milliseconds
while(!isOnEdge()) {
   java.lang.Thread.sleep(100);
}

//Okay sub is on edge, we can do our thing now
stopStroking();
sendMessage("Hold the edge!", 10);
endEdge();
sendMessage("Let go!");

So what does this exactly do? Well first of all it sends the message "Edge!" to the sub and waits for 0 seconds. The 0 is important here because by default the program adds a default delay after each message so the sub has the time to read it, however in this case we want to directly execute the next two statements. Afterwards it starts the metronome and registers the sub as edging. Then it checks whether the sub is on the edge every 100 MILLISECONDS. It does that by looping java.lang.Thread.sleep(100); while the sub is NOT on the edge. java.lang.Thread.sleep(x) waits/sleeps the current execution of the code for x milli seconds. In this case 100. If isOnEdge() returns true because the sub is on the edge it will exit this loop and will then continue with the following code.


How would I implement edging taunts?

Yes there is no native feature for this however it is quite easy to implement on your own. I think I can just give you a quick example so you understand how I would handle it:

//Call this function somewhere after loading/running this file first
function edge() {
   //Start stroking and send edging stuff
   sendMessage("Edge!", 0);
   startStroking(250);
   startEdge();
   //Start the edging taunts
   sendEdgeTaunts();
   //If this is executed the sub is on the edge and the taunt cycle was broken
   endEdge();
   //Yea do whatever you want to do now
   sendMessage("Okay, let's continue!");
}

function sendEdgeTaunts() {
   //Select a random amount of iterations and we will wait based on that random amount before sending a taunt message
   iterationsToGo = randomInteger(4, 12);
   
   //Just how long you want each iteration to take
   var millisecondsToWait = 500;
   //Start our loop and continue until iterationsToGo are equal or less than zero
   while(iterationsToGo > 0) {
      //Is the sub on the edge?
      if(isOnEdge()) {
         //Okay stop stroking and exit this loop and function
         stopStroking();
         sendMessage("You are on the edge!");
         return;
      }
      //Sub is not on edge, which means we subtract one from our iterations and wait for 500 milliseconds afterwards
      iterationsToGo--;
      java.lang.Thread.sleep(millisecondsToWait);
   }

   //You can chose a random fitting taunt message somehow here
   sendMessage("Come on!");
   //Start the whole thing all over again
   sendEdgeTaunts();
}

//Just a function to generate a random integer
function randomInteger(lowest, highest) {
   return Math.floor(Math.random() * highest) + lowest;
}

How does this work? Well it starts the edging process. Afterwards it checks whether the sub is on the edge every 500 milli seconds. If the sub is on the edge it will send the message "You are on the edge!" to the chat and exit the taunt cycle and go back to the edge() method. Now after this loop was run x times (iterationsToGo = randomInteger(4, 12);) it will exit the loop and send a message such as "Come on!" to the sub. Afterwards it will start all over again. This allows you to create stroking or edging taunts.