How Can We Help?

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:

1    // (onAdd)
2    (app, device, block) => {
3           app.log(“hat block of ${block.opcode} is add to workspace”);
4    }

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:

1    onRemove(app, device, block) {
2             app.log(“hat block of ${block.opcode} is remove from workspace”);
3    }

block.onRun

Function: Triggered when a hat block is executed

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

Example:

1    // Hat block example
2    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; } }

3

4    //Command block example
5    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(); }); }
6
7    Value block example
8    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); }); }