From dcc6d39927b67e3a3728d0bdcaccb9c337f04f13 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Fri, 8 May 2020 21:07:17 +0800 Subject: [PATCH] Update forEach --- _server/MotaAction.g4 | 2 +- libs/events.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index 84819759..8e6e44e4 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -1954,7 +1954,7 @@ return '{"type": "for", "name": "'+expression_0+'", "from": "'+EvalString_0+'", */; forEach_s - : '循环遍历' ': ' expression '在列表' JsonEvalString '中' BGNL? Newline action+ BEND Newline + : '循环遍历' ': 以' expression '逐项读取列表' JsonEvalString BGNL? Newline action+ BEND Newline /* forEach_s tooltip : forEach:循环遍历列表 diff --git a/libs/events.js b/libs/events.js index 437a7a3e..111bde5d 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1858,15 +1858,16 @@ events.prototype._action_for = function (data, x, y, prefix) { core.setFlag(toName, data.to); core.setFlag(stepName, data.step); var condition = "(function () {"+ + "var clearAndReturn = function (v) { if (!v) { core.removeFlag('"+toName+"'); core.removeFlag('"+stepName+"'); } return v; };"+ "var to = core.calValue(core.getFlag('" + toName + "'));"+ "var step = core.calValue(core.getFlag('" + stepName + "'));"+ - "if (typeof step != 'number' || typeof to != 'number') return false;"+ - "if (step == 0) return true;"+ + "if (typeof step != 'number' || typeof to != 'number') return clearAndReturn(false);"+ + "if (step == 0) return clearAndReturn(true);"+ "var currentValue = core.calValue('switch:'+'" + data.name.substring(7) + "', '"+prefix+"');"+ "currentValue += step;"+ "core.events._setValue_setSwitch('switch:'+'" + data.name.substring(7) + "', currentValue, '"+prefix+"');"+ - "if (step > 0) { return currentValue <= to; }"+ - "else { return currentValue >= to; }"+ + "if (step > 0) { return clearAndReturn(currentValue <= to); }"+ + "else { return clearAndReturn(currentValue >= to); }"+ "})()"; return this._action_dowhile({"condition": condition, "data": data.data}, x, y, prefix); }