Include a JS file
You can include another JS file in your code.
This can be a local (on our server) or remote JS file.
Include it like this:
$.getScript ( SOMEURL, SOMEFUNCTION );
This uses jQuery
getScript.
The JS script is loaded from SOMEURL.
This is
asynchronous.
At some point it returns and SOMEFUNCTION is called.
Your code elsewhere may need to check if the JS is loaded yet or not.
Notes:
- You need to avoid
mixed content.
The run is HTTPS so remote JS must be HTTPS.
- If you use P5, and need to load extra JS files,
load them inside the setup() function, not outside.
- If you are defining Worlds and Minds as classes
(which is the legacy way of doing it)
do not put them inside SOMEFUNCTION.
They must be in the global namespace.
Examples:
- Mind calling a Mind.
The calling Mind's getAction method repeatedly checks
to see if the JS of the other Mind is loaded yet.
- JS code search of all Worlds for use of getScript.
- Example of a World that uses getScript (see
source code):
Character recogn... 1949 runs ♦ 0 likes
By
"Coding Train" p... Created: 5 Jul 2019
Modified: 17 Sep 2023
Neural network to do character recognition from image database and from handwriting in real-time.
Multiple JS files
To break up your code into multiple JS files,
upload the extra JS files into your "Uploads" section.
You can edit them online with the "Edit" button on the Uploads page.
Your main World or Mind JS file
can then include those other JS files
as described above.
Worlds and Minds do not have to be on this site
Following on from the above,
Worlds and Minds do not have to be on this site.
You can develop Worlds and Minds on your own site, with your own development tools.
So long as they are JS at some URL.
You can then upload a
stub World or Mind to this site
which drags in the JS from your site at run-time.
This relates to
The AI model behind this site.