wait: get info
This commit is contained in:
parent
985d3d8294
commit
a9301f7cd9
@ -500,12 +500,12 @@ return code;
|
||||
*/;
|
||||
|
||||
wait_s
|
||||
: '等待用户操作'
|
||||
: '等待用户操作并获得按键或点击信息'
|
||||
|
||||
|
||||
/* wait_s
|
||||
tooltip : wait: 等待用户操作
|
||||
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=wait-%e7%ad%89%e5%be%85%e7%94%a8%e6%88%b7%e6%93%8d%e4%bd%9c
|
||||
tooltip : wait: 等待用户操作并获得按键或点击信息(具体用法看文档)
|
||||
helpUrl : https://ckcz123.github.io/mota-js/#/event?id=https://ckcz123.github.io/mota-js/#/event?id=wait%EF%BC%9A%E7%AD%89%E5%BE%85%E7%94%A8%E6%88%B7%E6%93%8D%E4%BD%9C
|
||||
colour : this.soundColor
|
||||
var code = '{"type": "wait"},\n';
|
||||
return code;
|
||||
|
||||
@ -54,7 +54,7 @@ core.setStatus('atk', 1000)
|
||||
|
||||
|
||||
core.getStatus('atk')
|
||||
返回当前攻击力数值。本句等价于 core.status.hero.atk
|
||||
返回当前攻击力数值。本句等价于 core.status.hero.atk。
|
||||
|
||||
|
||||
core.setHeroLoc('x', 5)
|
||||
|
||||
@ -252,14 +252,14 @@
|
||||
|
||||
``` js
|
||||
"x,y": [ // 实际执行的事件列表
|
||||
"你当前的攻击力是${status:atk}, 防御是${status:def}",
|
||||
"你当前的攻击力是${status:atk}, 防御是${status:def},坐标是(${status:x},${status:y})",
|
||||
"你的攻防和的十倍是${10*(status:atk+status:def)}",
|
||||
"你的红黄蓝钥匙总数为${item:yellowKey+item:blueKey+item:redKey}",
|
||||
"你访问某个老人的次数为${flag:man_times}",
|
||||
]
|
||||
```
|
||||
|
||||
- `status:xxx` 获取勇士属性时只能使用如下几个:hp(生命值),atk(攻击力),def(防御力),mdef(魔防值),money(金币),experience(经验)。
|
||||
- `status:xxx` 获取勇士属性时只能使用如下几个:hp(生命值),atk(攻击力),def(防御力),mdef(魔防值),money(金币),experience(经验),x(勇士的横坐标),y(勇士的纵坐标),direction(勇士的方向)。
|
||||
- `item:xxx` 中的xxx为道具ID。所有道具的ID定义在items.js中,请自行查看。例如,`item:centerFly` 代表中心对称飞行器的个数。
|
||||
- `flag:xxx` 中的xxx为一个自定义的变量/Flag;如果没有对其进行赋值则默认值为false。
|
||||
|
||||
@ -521,10 +521,6 @@ name是可选的,代表目标行走图的文件名。
|
||||
]
|
||||
```
|
||||
|
||||
### wait:等待用户操作
|
||||
|
||||
使用 `{"type": "wait"}` 可以等待用户进行操作(如点击、回车等)。
|
||||
|
||||
### battle: 强制战斗
|
||||
|
||||
调用battle可强制与某怪物进行战斗(而无需去触碰到它)。
|
||||
@ -1118,6 +1114,46 @@ choices为一个数组,其中每一项都是一个选项列表。
|
||||
|
||||
!> 如果continue事件不在任何循环中被执行,则和exit等价,即会立刻结束当前事件!
|
||||
|
||||
### wait:等待用户操作
|
||||
|
||||
使用 `{"type": "wait"}` 可以等待用户进行操作(如点击、按键等)。
|
||||
|
||||
当用户执行操作后:
|
||||
- 如果是键盘的按键操作,则会将flag:type置为0,并且把flag:keycode置为刚刚按键的keycode。
|
||||
- 如果是屏幕的点击操作,则会将flag:type置为1,并且设置flag:x和flag:y为刚刚的点击坐标。
|
||||
|
||||
下面是一个while事件和wait合并使用的例子,这个例子将不断接收用户的点击或按键行为,并输出该信息。
|
||||
如果用户按下了ESC或者点击了屏幕正中心,则退出循环。
|
||||
|
||||
|
||||
``` js
|
||||
"x,y": [ // 实际执行的事件列表
|
||||
{"type": "while", "condition": "true", // 永久循环
|
||||
"data": [
|
||||
{"type": "wait"}, // 等待用户操作
|
||||
{"type": "if", "condition": "flag:type==0", // flag:type==0,键盘按键
|
||||
"true": [
|
||||
"你当前按键了,keycode是${flag:keycode}",
|
||||
{"type": "if", "condition": "flag:keycode==27", // ESC的keycode是27
|
||||
"true": [{"type": "break"}], // 跳出循环
|
||||
"false": []
|
||||
}
|
||||
],
|
||||
"false": [ // flag:type==1,鼠标点击
|
||||
"你当前点击屏幕了,坐标是[${flag:x},${flag:y}]",
|
||||
{"type": "if", "condition": "flag:x==6 && flag:y==6", // 点击(6,6)
|
||||
"true": [{"type": "break"}], // 跳出循环
|
||||
"false": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
|
||||
### function: 自定义JS脚本
|
||||
|
||||
上述给出了这么多事件,但有时候往往不能满足需求,这时候就需要执行自定义脚本了。
|
||||
|
||||
@ -715,7 +715,7 @@ actions.prototype.longClick = function () {
|
||||
core.drawText();
|
||||
return true;
|
||||
}
|
||||
if (core.status.event.id=='action' && (core.status.event.data.type=='text' || core.status.event.data.type=='wait')) {
|
||||
if (core.status.event.id=='action' && core.status.event.data.type=='text') {
|
||||
core.doAction();
|
||||
return true;
|
||||
}
|
||||
@ -728,7 +728,7 @@ actions.prototype.keyDownCtrl = function () {
|
||||
core.drawText();
|
||||
return;
|
||||
}
|
||||
if (core.status.event.id=='action' && (core.status.event.data.type=='text' || core.status.event.data.type=='wait')) {
|
||||
if (core.status.event.id=='action' && core.status.event.data.type=='text') {
|
||||
core.doAction();
|
||||
return;
|
||||
}
|
||||
@ -769,11 +769,20 @@ actions.prototype.keyUpConfirmBox = function (keycode) {
|
||||
////// 自定义事件时的点击操作 //////
|
||||
actions.prototype.clickAction = function (x,y) {
|
||||
|
||||
if (core.status.event.data.type=='text' || core.status.event.data.type=='wait') {
|
||||
if (core.status.event.data.type=='text') {
|
||||
// 文字
|
||||
core.doAction();
|
||||
return;
|
||||
}
|
||||
if (core.status.event.data.type=='wait') {
|
||||
core.setFlag('type', 1);
|
||||
core.setFlag('x', x);
|
||||
core.setFlag('y', y);
|
||||
core.status.route.push("input:"+(10000+100*x+y));
|
||||
core.doAction();
|
||||
return;
|
||||
}
|
||||
|
||||
if (core.status.event.data.type=='choices') {
|
||||
// 选项
|
||||
var data = core.status.event.data.current;
|
||||
@ -811,7 +820,14 @@ actions.prototype.keyDownAction = function (keycode) {
|
||||
|
||||
////// 自定义事件时,放开某个键的操作 //////
|
||||
actions.prototype.keyUpAction = function (keycode) {
|
||||
if ((core.status.event.data.type=='text' || core.status.event.data.type=='wait') && (keycode==13 || keycode==32 || keycode==67)) {
|
||||
if (core.status.event.data.type=='text' && (keycode==13 || keycode==32 || keycode==67)) {
|
||||
core.doAction();
|
||||
return;
|
||||
}
|
||||
if (core.status.event.data.type=='wait') {
|
||||
core.setFlag('type', 0);
|
||||
core.setFlag('keycode', keycode);
|
||||
core.status.route.push("input:"+keycode);
|
||||
core.doAction();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -761,8 +761,27 @@ events.prototype.doAction = function() {
|
||||
}
|
||||
break;
|
||||
case "wait":
|
||||
if (core.status.replay.replaying)
|
||||
core.events.doAction();
|
||||
if (core.status.replay.replaying) {
|
||||
var code = core.status.replay.toReplay.shift();
|
||||
if (code.indexOf("input:")==0) {
|
||||
var value = parseInt(code.substring(6));
|
||||
core.status.route.push("input:"+value);
|
||||
if (value>=10000) {
|
||||
core.setFlag('type', 1);
|
||||
core.setFlag('x', parseInt((value-10000)/100));
|
||||
core.setFlag('y', value%100);
|
||||
}
|
||||
else {
|
||||
core.setFlag('type', 0);
|
||||
core.setFlag('keycode', value);
|
||||
}
|
||||
core.events.doAction();
|
||||
}
|
||||
else {
|
||||
core.stopReplay();
|
||||
core.drawTip("录像文件出错");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "revisit": // 立刻重新执行该事件
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user