Documentation
Script

Script

⚠️

This page is under construction.

⚠️

Beta feature, subject to change.

Script allows you to execute scripts and interact with the game.

scene.action([
    new Script(({ storable }) => {
        console.log("This script is being executed.");
 
        // ask the user for input
        const price = prompt("How much do you want to pay for this item?");
        const namespace = storable.getNamespace("test");
 
        if (!isNaN(price)) {
            namespace.set("price", price);
        }
    })
]);

Public Methods

constructor

  • handler: (ctx: ScriptCtx) => void - When the script is executed, this handler will be called. The handler will receive a ScriptCtx object.
⚠️

The handler function should return a cleanup function if it has any side effects.
The cleanup function will be called when the player undo the action.

new Script((ctx) => {
    const token = setTimeout(() => {
        console.log("This script is being executed.");
    }, 1000);
 
    return () => clearTimeout(token);
})
const script = new Script((ctx) => {
    console.log(ctx.gameState);
});