PythonScript Class

Extends Script
Module: Script

Python scripts are similar to Script object by are written using the Python programming language.

Support for Python is provided using the Brython (https://github.com/brython-dev/brython) transpiler.

It is not possible to include external python code and libraries to the script.

Item Index

Properties

Attributes

Methods

appData

(
  • data
)

Call onAppData() from the script if available.

This method is called everytime that external data is passed to the runtime.

Parameters:

  • data Object

compileCode

(
  • code
)

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.

Parameters:

  • code String

    Code to be compiled into usable code.

dispose

()

Disposes the script, can be used to clear resources when the program exits.

Calls the script dispose method if it exists.

resize

()

Call resize method if available.

The resize method receives width and height as arguments.

update

()

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.

Properties

code

String

Python code attached to the script.

It only has acess to the data provided as parameter in each method.

  • initialize(obj, scene, program, keyboard, mouse)
    • Called on app initialization, its called after all children elements are initialized, its safe to apply operations on other objects inside this method.
  • update(delta, obj, scene, program, keyboard, mouse)
    • Called on every frame after rendering
  • dispose(obj, scene, program, keyboard, mouse)
    • Called when disposing the program
  • onMouseOver(intersections, obj, scene, program, keyboard, mouse)
    • Called on every frame if mouse is on top of one of the script children
    • Receives an intersections array as argument.
  • onResize(x, y, obj, scene, program, keyboard, mouse)
    • Called every time the window is resized
    • Receives width and height as parameters
  • onAppData(data, obj, scene, program, keyboard, mouse)
    • Called when receiving data sent by the host website

program

Program

Reference to the program object.

Can be used to access other scenes, get resources and objects.

scene

Scene

Reference to the scene where the script is placed.

Can be used to interact with other objects.

Attributes

DEFAULT

String

Default script code used when creating a new Script.

script

Function

Compiled function used during runtime.

This varible gets created using the compileCode() function called automatically on initalization.