Block Event Handler (Live Mode Configuration)

block.onAdd

Function: Triggered when you add a hat block to the operation area

Note: This function is available in both the editing and playing states of a project. Usually, when a project is loaded, the virtual machine has already loaded the block, and so this function is triggered. In addition, when device.resetEvents is executed, this function is also triggered.

Example:

// (onAdd)
(app, device, block) => {
    app.log("hat block of ${block.opcode} is add to workspace");
}

block.onRemove

Function: Triggered when you remove a hat block from the operation area

Note: This function is available in both the editing and playing states of a project. Usually, when a project is loaded, the virtual machine has already loaded the block, and so this function is triggered. In addition, when device.resetEvents is executed, this function is also triggered.

Example:

onRemove(app, device, block) {
    app.log("hat block of ${block.opcode} is remove from workspace");
}

block.onRun

Function: Triggered when a hat block is executed

Note: The type of the returned value varies according to block type.

Example: ```js // example of hat block async onRun(args, app, device, block) { app.log("block of ${block.opcode} is checked to trigger"); if (args.ARGMENT1 > 100) { app.log("block of ${block.opcode} is condition satisfied, start this thread running"); return true; } else { app.log("block of ${block.opcode} is not condition satisfied, prohabit this thread from running"); return false; } }

// example of command block async onRun(args, app, device, block) { app.log("block of ${block.opcode} is running"); // you can use promise to return laterly, or you can return immidiately return new Promise((resolve)=>{ resolve(); }); }

// example of value block async onRun(args, app, device, block) { app.log("block of ${block.opcode} is running"); // you can use promise to return laterly, or you can return immidiately return new Promise((resolve)=>{ window.settimeout(()=>app.log("block of ${block.opcode} is stoped then, return value of 100")); resolve(100); }); } ```

results matching ""

    No results matching ""