Discord

MYWorld API - Adding Scripting

MyScript is based on Javascript.

Select an object and click "Edit Script"

To test, press the play button

Handling a click

    function onClick(my){
        my.position.x++;
    }

Available properties: my.position, my.rotation, my.scaling

e.g. my.rotation.y = 0.1;

Doing something every frame

    function onFrame(my) {
        my.rotation.y += 0.001;
    }

Find a submesh

     var button1 = my.find("Button1");

Play a sound

    my.playSound("urltosound.mp3");

Doing something when the space starts

    function onStart(my) {
        my._variable = 10;
    }

Moving, rotating, and scaling

function onClick(my) { my.position.x = 5; my.position.y = 1; my.position.z = 2; // rotate by 45 degrees. We must convert to radians first. my.rotation.y = 45 * Math.PI / 180.0; // increase the z scale by 1 my.scaling.z += 1; }

Moving with collisions

    function onClick(my) {
        my.move(5, 1, 2);
    }

This moves the object to 5,1,2 but uses the collision system to collide with other objects

Sharing Global Variables

Create a cube and attach this script:

    var SomeObject; // declared outside a function = global
    function onClick(my) {
        SomeObject = my;
    }

Now add a sphere

In the sphere's script we can access the SomeObject variable that was set to point to the cube.

    function onClick(my) {
        SomeObject.rotation.y += 0.1;
    }