Bring the world to life

TypeScript

TypeScript gives creators a readable way to add logic to a world. Scripts run through the game's JavaScript engine and can coordinate interaction, animation, music, and sound.

app.ts
function boot() {
  // Place your game logic here
  // Make the world come alive
}
Reference Every object a script can reach, and how each behaves Animation How movement is described, and left to run

The idea

Connect actions to reactions.

An interactive world.

A world becomes interactive when an event can cause a useful response. A switch might operate a platform, an object might animate, or a moment in the course might change the music. TypeScript provides structure and useful checking while creators write those relationships.

Here we have an example of TypeScript talking to our game engine, telling it what to do when the ball is loaded into a catapult. The platform rises up, turns to its target, then fires, before returning back to its original position.

// When the catapult is loaded, rotate, aim, and fire
catapult.onBallLoaded = () => {
    launchpad
        .animate("local-y(0.2, 2, sine-inout)")
        .then("rotate-y(120, 3, sine-inout)")
        .delay(1)
        .reverse();
    game.setTimeout(() => catapult.fire(), 7000);
}

Learning path

Start small. Build confidence.

01

Events

Understand when a script runs and what information an event provides.

02

Objects

Work with supported world objects and their documented capabilities.

03

Reusable logic

Organize behavior into small pieces that remain understandable and testable.

A first script

What a script looks like.

A switch is thrown, a platform answers. The shape below is illustrative: the published reference will list the interfaces each game version actually supports.

// Raise a platform while a switch is held down.
class LiftedPlatform {
    private readonly speed: number = 3.5;
    private target: Vector3;

    constructor(private platform: WorldObject, private lift: number) {
        this.target = platform.position.offset(0, lift, 0);
    }

    onSwitch(state: boolean): void {
        const destination = state ? this.target : this.platform.origin;
        this.platform.moveTo(destination, this.speed);
        world.playSound(state ? "lift-rise" : "lift-fall");
    }
}

The same block without the numbered class renders without a gutter:

world.onReady(() => {
    const gate = world.find("north-gate");
    gate.onEnter((player) => world.award(player, 50));
});

Documentation

Guides first, reference when needed.

Two pages carry the detail. The reference describes every object a script can reach, what each one is for, and how it behaves. The animation guide covers the way behaviour is actually expressed: one call describing a movement, and the engine running it from there.

Both name the version of the game they describe, because a script can only use what its own copy of the game supports.

Explore Parametric CAD