To edit code in the browser,
we use the
and syntax checking.
Run from editor
You can run direct from the editor using the "Run" button.
But note it runs the saved version, not the text currently in the editor (if not saved).
Browser - Force reload
Developing in a browser can conflict with the fact that the browser caches files
to speed up browsing.
This site uses
a "cache buster"
to effectively disable caching for World and Mind JS.
But it does not disable caching
for other user-submitted files (World and user images, and uploads, which may include more JS).
if you are working with these other files,
you may need to force the browser to go back to the server for the latest copy,
rather than displaying the cached version.
so this site supports
for those who want to hide their code.
If you want to make it difficult for people to copy/modify your code,
you can save the JS in an obfuscated (also minimised) form.
The obfuscated JS is the version visible online, and the version that runs when you click Run.
The plain text JS is saved on our server.
When you Edit,
the plain text version is always loaded.
Only the owner can see this.
Obfuscation is optional and is off by default.
When you Edit, you will see an option
like the following
to save the public JS in an obfuscated form
or in plain text:
Trying to de-obfuscate someone's obfuscated JS
is against our
Include another 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 );
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.
Do not put the World definition or Mind definition inside SOMEFUNCTION.
They must be in the global namespace.
Need to avoid
The run is HTTPS so remote JS must be HTTPS.
Examples of including another JS file:
Mind calling a Mind.
Mind is defined outside of SOMEFUNCTION.
SOMEFUNCTION sets a variable to show the JS is now loaded.
Mind's getAction method repeatedly checks that variable to see if the JS is loaded yet.
Purple Fruit Monster.
This is a port of some JS that does not use a World class or Mind class at all.
It just needs a JS library loaded before the main JS runs.
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.