All Worlds and Minds are written in
JavaScript (JS).
They all run on your machine in the browser (not on the server).
All Worlds and Minds can be written in the browser.
No install is needed to write them or run them.
JavaScript is an important programming language.
It is the
dominant language on the Web on the browser side
(and also important on the server side).
Some
surveys
rank
it as the most important programming language in the world.
It is a valuable skill for a tech career.
Edit in browser
To edit code in the browser,
we use the
Ace
editor.
This does JavaScript syntax highlighting
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).
Outputting data
Your run can output arbitrary amounts of data
(debug information, data created during a run, etc.)
with the following:
Output to console in run window, using
console.log.
See a JS code search of all Worlds for use of console.log.
Display in the run header, using
AB.msg.
See a JS code search of all Worlds for use of AB.msg.
Save data to disk on the server, using
AB.saveData.
See a JS code search of all Worlds for use of AB.saveData.
Obfuscate your JavaScript
The nature of JavaScript is that the source code is visible,
so this site supports
built-in obfuscation
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:
Obfuscated code is exempt from the JS code site search.
Trying to de-obfuscate someone's obfuscated JS
is against our
terms of use.
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 );
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:
If you use P5, and need to load extra JS files,
load them inside the setup() function, not outside.
If you are defining World and Mind classes, do not put them inside SOMEFUNCTION.
They must be in the global namespace.
You need to avoid
mixed content.
The run is HTTPS so remote JS must be HTTPS.
Examples of including another JS file:
Mind calling a Mind.
The calling Mind's getAction method repeatedly checks
to see if the JS of the other Mind is loaded yet.
Code of
Purple Fruit Monster.
This is a port of some JS that just needs a JS library loaded before the main JS runs.
JS code search of all Worlds for use of getScript.
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.