diff --git a/catroid/src/androidTest/assets/catrobatTests/bricks/control/testForLoopWithChangeVariableBrick.catrobat b/catroid/src/androidTest/assets/catrobatTests/bricks/control/testForLoopWithChangeVariableBrick.catrobat new file mode 100644 index 00000000000..e7f8c916071 Binary files /dev/null and b/catroid/src/androidTest/assets/catrobatTests/bricks/control/testForLoopWithChangeVariableBrick.catrobat differ diff --git a/catroid/src/androidTest/assets/catrobatTests/bricks/control/testForVariableFromToBrick.catrobat b/catroid/src/androidTest/assets/catrobatTests/bricks/control/testForVariableFromToBrick.catrobat index 2a37b6fd12f..2d123ce53f9 100644 Binary files a/catroid/src/androidTest/assets/catrobatTests/bricks/control/testForVariableFromToBrick.catrobat and b/catroid/src/androidTest/assets/catrobatTests/bricks/control/testForVariableFromToBrick.catrobat differ diff --git a/catroid/src/main/java/org/catrobat/catroid/content/actions/ForVariableFromToAction.java b/catroid/src/main/java/org/catrobat/catroid/content/actions/ForVariableFromToAction.java index 9d6cd7397c9..4b9818ab390 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/actions/ForVariableFromToAction.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/actions/ForVariableFromToAction.java @@ -40,7 +40,6 @@ public class ForVariableFromToAction extends LoopAction { private boolean isRepeatActionInitialized = false; private int fromValue; private int toValue; - private int executedCount = 0; private int step = 1; @Override @@ -55,16 +54,15 @@ public boolean delegate(float delta) { isCurrentLoopInitialized = true; } - setControlVariable(fromValue + step * executedCount); setCurrentTime(getCurrentTime() + delta); if (action != null && action.act(delta) && !isLoopDelayNeeded()) { - executedCount++; - - if (Math.abs(step * executedCount) > Math.abs(toValue - fromValue)) { + if (!(controlVariable.getValue() instanceof Double) + || (step > 0 && (double) controlVariable.getValue() >= toValue) + || (step < 0 && (double) controlVariable.getValue() <= toValue)) { return true; } - + changeControlVariable(step); isCurrentLoopInitialized = false; action.restart(); } @@ -75,7 +73,6 @@ public boolean delegate(float delta) { public void restart() { isCurrentLoopInitialized = false; isRepeatActionInitialized = false; - executedCount = 0; super.restart(); } @@ -101,6 +98,7 @@ private boolean interpretParameters() { Double toInterpretation = to == null ? Double.valueOf(0d) : to.interpretDouble(scope); toValue = toInterpretation.intValue(); setStepValue(); + setControlVariable(fromValue); return true; } catch (InterpretationException interpretationException) { Log.d(getClass().getSimpleName(), "Formula interpretation for this specific Brick failed.", interpretationException); @@ -115,4 +113,8 @@ private void setStepValue() { private void setControlVariable(int value) { controlVariable.setValue((double) value); } + + private void changeControlVariable(int value) { + controlVariable.setValue((double) controlVariable.getValue() + (double) value); + } }