积木回调事件(在线运行处理配置)

block.onAdd

功能: 当帽子头(hat block)被添加到工作区。

注意: 不仅在编辑状态有效,在播放模式同样有效,通常是作品加载时,virtual machine 已经加载了积木块,会触发此函数,另外当 device.resetEvents 时,也会重新触发此事件。

示例:

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

block.onRemove

功能: 当帽子头(hat block)被移出工作区。

注意: 不仅在编辑状态有效,在播放模式同样有效,通常是作品加载时,virtual machine 已经加载了积木块,会触发此函数,另外当 device.resetEvents 时,也会重新触发此事件。

示例:

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

block.onRun

功能: 当积木块运行。

注意: 根据积木块的类型,帽子头/命令块/值块,返回值的类型不同。

示例: ```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 ""