genome231 wrote: ↑Fri Mar 22, 2019 7:38 am
Thanks!
1 more.
How would you write a piece of code so it only runs once?
Like in the beginning when i want to set the required variables?
EDIT: Found the solution to the above on https://github.com/GodDragoner/TeaseAIJ ... le-Methods:
Second question:
If I want to update a variable, can it be done this way:
?
Or would it have to be something like:
?
Best regards
Genome
So, first off, I recommend loading all of your variables an everything in the onload.js file which will get run when the personality is selected.
For your question about the variables, let me explain it a bit more in depth so you fully understand. So, in a programming language, if you say x = 2. This variable is being stored in ram and will only be accessible while the program is running. Furthermore, variables also have something called a scope as GodDragon was mentioning. So for example:
Code: Select all
var y = 1;
while ( y < 7)
{
y = y + 1;
var x = 6;
}
x = x + 1;
This code would give an error because var x was defined inside of the while loop and therefore it's scope is limited to the while loop so after we exit the while loop, it's as if it no longer exists.
So, if you execute the following statement:
What this is really doing is saying, "create a local variable in ram and set the value to whatever the value of "varx" is."
So, if you change the value of x, it will change the value of your local copy in ram. However, it won't change the value in the file where it is stored which is why you need to do:
if you want to change the value of a variable.
If it still doesn't make sense let me know and I can try to explain it more or do some searching on "Scoping".
ilikelatex wrote: ↑Sun Mar 24, 2019 10:53 am
I have also a short question is it possible to call a specific function when you run a file or do i have to handle it in the file itself with flags?
Code: Select all
@Call(Custom\AV_Scripts\AV_Mistress.txt, promise)
->
run("Custom" + java.io.File.separator + "AV_Scripts" + java.io.File.separator + "AV_Mistress.js"); //, promise())
I see what you're asking and I've looked at ways of doing this myself as well. So, here is my current opinion on how to do this:
With my script converter, it creates a bunch of functions inside of the files including one at the beginning called main(). It also executes main() on the very first line of the file. If you have a file where you want to execute a specific method in the file instead of just running from the beginning, rename the file's main function to something unique like <filename>main. Then to accomplish what you showed above, do the following:
This takes advantage of the fact that once a file has been run in javascript, its functions are available to be called. And, if you make the main function not execute automatically, then all the run(<filename>) is doing is making sure all the methods are available. One thing to watch out for here. If you use this approach, make sure any other time you want to run that file from the beginning, you're also going to now have to do:
so that it will actually execute the main function.
Alternatively, you could use flags if you want instead.