Contents#

The following page contains information on a variety of Open Wonderland development topics. Often, I'll find a piece of code interesting or important to refer to later. In such a case, I'll put it here and document it where needed.

Scripting#

Global Variables#

Every scripting environment attached to a cell has two global variables: Context, and cell.

Variable Description
Context Main access point for controlling callbacks and triggers in a script.

Most often the Context variable is used to assign new callbacks and triggers.
cell Pointer to the Wonderland cell that effectively encapsulates the scripting environment.

Most often the cell variable is passed as an argument to scripting commands.

  • Context
    • Examples of using the Context variable include:
      • The first letter in the Context variable's name is capitalized due to the fact that JavaScript has a native global variable called: context
Context.enableMouseEvents();
Context.onClick(someFunction, true_of_false);

  • Cell
    • Examples of using the cell variable include:
spin(cell, 1, 1);

Callbacks#

Callbacks act as event handlers, or in other words, reactions to a user's interactions. For example, clicking on an object.

Callbacks have locality. This means that the scripter can choose whether or not the reactions to their events happen only on their client or on all clients. This is desirable to use when the script uses a command that requires network involvement.

All callbacks are invoked by appending the Context variable to the beginning of the event name:

Context.onClick(function_name, true_or_false);

Event Description
onClick When a user clicks the mouse.
onMouseEnter When a user moves the mouse over an object.
onMouseExit When a user moves the moss off an object.
onKeyPress When a user has moused over an object and pressed a specific key on the keyboard.
onApproach When a user walks sufficiently close to an object.
onExit When a user walks away from an object.

Triggers#

Sample Scripts#

These scripts were used during the iED 2011 EZScript workshop
//spin molecule
spin(cell, 1, 5);

//spin + click
Context.enableMouseEvents();

function click() {

spin(cell, 1, 5);
}
Context.onClick(click, false);

//spin + click + highlight
Context.clearCallbacks();
Context.enableMouseEvents();

function click() {
 spin(cell, 1, 5);
}

function highlight() {
HighlightCell(cell, true, 'white');
}

function unhighlight() {
HighlightCell(cell, false, 'white');
}

Context.onClick(click, false);
Context.onMouseEnter(highlight, false);
Context.onMouseExit(unhighlight, false);

//highlight
Context.clearCallbacks();
Context.enableMouseEvents();

function highlight() {
HighlightCell(cell, true, 'white');
}

function unhighlight() {
HighlightCell(cell, false, 'white');
}

Context.onMouseEnter(highlight, false);
Context.onMouseExit(unhighlight, false);

//spin and move plane
animateMove(cell, 0, 0, 1, 3);
spin(cell, .25, 1);
animateMove(cell, 1, 0, 0, 3);
spin(cell, .25, 1);
animateMove(cell, 0, 0, -1, 3);
spin(cell, -.25, 1);
animateMove(cell, -1, 0, 0, 3);
spin(cell, -.25, 1);

//highlight
Context.clearCallbacks();
Context.enableMouseEvents();

function highlight() {
HighlightCell(cell, true, 'white');
}

function unhighlight() {
HighlightCell(cell, false, 'white');
}

Context.onMouseEnter(highlight, false);
Context.onMouseExit(unhighlight, false);

//open door
Context.clearCallbacks();
Context.enableMouseEvents();
Context.enableProximityEvents();

function open() {
 spin(cell, 0.25, 2);
}


function close() {
  spin(cell, 0, 1);
}

Context.onLeave(close, false);
Context.onClick(open, false);

//NPC talking
Context.enableProximityEvents();

function SayHello() {
  ShowHUDMessage("Hello, Welcome to Open Wonderland!");
}

function SayGoodbye() {
  ShowHUDMessage("Talk to you soon! Bye!");
}

Context.onApproach(SayHello, true);
Context.onLeave(SayGoodbye, true);

//NPC walking in a circle
var x;
for(x = 0; x < 20; x++) {
  MoveNpcForward(cell);
  MoveNpcLeft(cell);
}

Often times a developer will want to manipulate the HUD or Head's Up Display. When this occurs, one must remember to call the code on the AWT Event Queue like so:
SwingUtilities.invokeLater(new Runnable() { 
    public void run() {
    
    }
});

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-10) was last changed on 20-May-2011 17:19 by 128.206.170.200