Async function
This commit is contained in:
parent
a6a7671543
commit
5401714b3f
@ -1490,15 +1490,16 @@ return code;
|
|||||||
|
|
||||||
|
|
||||||
function_s
|
function_s
|
||||||
: '自定义JS脚本' BGNL? Newline RawEvalString Newline BEND Newline
|
: '自定义JS脚本' '不自动执行下一个事件' Bool BGNL? Newline RawEvalString Newline BEND Newline
|
||||||
|
|
||||||
|
|
||||||
/* function_s
|
/* function_s
|
||||||
tooltip : 可双击多行编辑,请勿使用异步代码。常见API参见文档附录。
|
tooltip : 可双击多行编辑,请勿使用异步代码。常见API参见文档附录。
|
||||||
helpUrl : https://h5mota.com/games/template/docs/#/event?id=function%EF%BC%9A%E8%87%AA%E5%AE%9A%E4%B9%89js%E8%84%9A%E6%9C%AC
|
helpUrl : https://h5mota.com/games/template/docs/#/event?id=function%EF%BC%9A%E8%87%AA%E5%AE%9A%E4%B9%89js%E8%84%9A%E6%9C%AC
|
||||||
default : ["alert(core.getStatus(\"atk\"));"]
|
default : [false,"alert(core.getStatus(\"atk\"));"]
|
||||||
colour : this.dataColor
|
colour : this.dataColor
|
||||||
var code = '{"type": "function", "function": "function(){\\n'+JSON.stringify(RawEvalString_0).slice(1,-1).split('\\\\n').join('\\n')+'\\n}"},\n';
|
Bool_0 = Bool_0?', "async": true':'';
|
||||||
|
var code = '{"type": "function"'+Bool_0+', "function": "function(){\\n'+JSON.stringify(RawEvalString_0).slice(1,-1).split('\\\\n').join('\\n')+'\\n}"},\n';
|
||||||
return code;
|
return code;
|
||||||
*/;
|
*/;
|
||||||
|
|
||||||
@ -2225,7 +2226,7 @@ ActionParser.prototype.parseAction = function() {
|
|||||||
var func = data["function"];
|
var func = data["function"];
|
||||||
func=func.split('{').slice(1).join('{').split('}').slice(0,-1).join('}').trim().split('\n').join('\\n');
|
func=func.split('{').slice(1).join('{').split('}').slice(0,-1).join('}').trim().split('\n').join('\\n');
|
||||||
this.next = MotaActionBlocks['function_s'].xmlText([
|
this.next = MotaActionBlocks['function_s'].xmlText([
|
||||||
func,this.next]);
|
data.async||false,func,this.next]);
|
||||||
break;
|
break;
|
||||||
case "update":
|
case "update":
|
||||||
this.next = MotaActionBlocks['update_s'].xmlText([
|
this.next = MotaActionBlocks['update_s'].xmlText([
|
||||||
|
|||||||
@ -1610,6 +1610,8 @@ core.insertAction([
|
|||||||
// 请勿直接调用 core.changeFloor(toFloor, ...),这个代码是异步的,会导致事件处理和录像出问题!
|
// 请勿直接调用 core.changeFloor(toFloor, ...),这个代码是异步的,会导致事件处理和录像出问题!
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!> 从V2.5.3开始,提供了一个"不自动执行下一个事件"的选项(`"async": true`)。如果设置了此项,那么在该部分代码执行完毕后,不会立刻执行下一个事件。你需要在脚本中手动调用`core.events.doAction()`来执行下一个事件。可以通过此项来实现一些异步的代码,即在异步函数的回调中再执行下一个事件。使用此选项请谨慎,最好向开发者寻求咨询。
|
||||||
|
|
||||||
## 同一个点的多事件处理
|
## 同一个点的多事件处理
|
||||||
|
|
||||||
我们可以发现,就目前而且,每个点的事件是和该点进行绑定,并以该点坐标作为唯一索引来查询。
|
我们可以发现,就目前而且,每个点的事件是和该点进行绑定,并以该点坐标作为唯一索引来查询。
|
||||||
|
|||||||
@ -1053,14 +1053,19 @@ events.prototype.doAction = function() {
|
|||||||
case "function":
|
case "function":
|
||||||
{
|
{
|
||||||
var func = data["function"];
|
var func = data["function"];
|
||||||
if (core.isset(func)) {
|
try {
|
||||||
if ((typeof func == "string") && func.indexOf("function")==0) {
|
if (core.isset(func)) {
|
||||||
eval('('+func+')()');
|
if ((typeof func == "string") && func.indexOf("function")==0) {
|
||||||
|
eval('('+func+')()');
|
||||||
|
}
|
||||||
|
else if (func instanceof Function)
|
||||||
|
func();
|
||||||
}
|
}
|
||||||
else if (func instanceof Function)
|
} catch (e) {
|
||||||
func();
|
console.log(e);
|
||||||
}
|
}
|
||||||
this.doAction();
|
if (!data.async)
|
||||||
|
this.doAction();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "update":
|
case "update":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user