Script objects are used to control other objects present in the scene.
These scripts can access everything inside of the program where they are running they should be used to control logic aspect of the application.
Its possible to extend these scripts by using libraries that can be imported using the include() function provided. Libraries can be stored locally on the project or loaded from remote sources.
Call onAppData() from the script if available.
This method is called everytime that external data is passed to the runtime.
Prepare the script code to be run. The script can be prepared using different methods depending on the include mode defined.
Can be used to dinamically change the script code. However it is not recommended can lead to undefined behavior.
Funtion called when the code is ready.
Create a object to access the context of this script.
Also includes the access to three cannon and nunu methods.
Context object for the script to access data.
Disposes the script, can be used to clear resources when the program exits.
Calls the script dispose method if it exists.
Get includes from the code, includes are fetched from the resource manager or if not found fetched using XHR.
Used to extract includes from code when loading libraries in APPEND mode.
The imported source is evaluated and loaded in the context of the script.
Global declarations need to be cleaned using the dipose method.
Initialize script, code automatically called by the runtime on program initialization.
Compiles the script code and calls the script initialize method if it exists after the code is compiled.
Remove includes from code.
Used to remove include statements when initializing code in APPEND mode.
Call resize method if available.
The resize method receives width and height as arguments.
Update script state automatically calls for mouse events if they are defined and for the script update method.
This method is executed every frame, script logic should not relly on the frame time, use the "delta" value provided.
Source code attached to the script, by default it is a Javacript source but other languages can be implemented.
It can access and change every object in the program and supports some events
- Called on app initialization, its called after all children elements are initialized, its safe to apply operations on other objects inside this method.
- Called on every frame after rendering
- Called when disposing the program
- Called on every frame if mouse is on top of one of the script children
- Receives an intersections array as argument.
- onResize(x, y)
- Called every time the window is resized
- Receives width and height as parameters
- Called when receiving data sent by the host website
Code written inside scripts have access to the following attributes:
- Same as this reference but global in the script scope
There is also access to the following functions
Can be APPEND, EVALUATE or INCLUDE.
APPEND mode with append the library code to the script code, when running in this mode the include method cannot be used during runtime
EVALUATE node with evaluate the library code during runtime, include method may still be used.
INCLUDE mode will include the file as a global script, these libraries are not unloaded after the script or application is terminated.
Reference to the program object.
Can be used to access other scenes, get resources and objects.
Reference to the scene where the script is placed.
Can be used to interact with other objects.
Append libraries on initialization.
Libraries are appended to the script code on initialization.
Evaluate libs during runtime.
This allows to load new libs during runtime, but its not possible to access private statements.