Skip to content

Commit 9d29597

Browse files
authored
Merge pull request #4685 from Rawbat/CATROID-1462
CATROID-1462 Change variable by "" brick does not work
2 parents 660004e + 5bee466 commit 9d29597

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

catroid/src/main/java/org/catrobat/catroid/content/actions/ForVariableFromToAction.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class ForVariableFromToAction extends LoopAction {
4040
private boolean isRepeatActionInitialized = false;
4141
private int fromValue;
4242
private int toValue;
43-
private int executedCount = 0;
4443
private int step = 1;
4544

4645
@Override
@@ -55,16 +54,15 @@ public boolean delegate(float delta) {
5554
isCurrentLoopInitialized = true;
5655
}
5756

58-
setControlVariable(fromValue + step * executedCount);
5957
setCurrentTime(getCurrentTime() + delta);
6058

6159
if (action != null && action.act(delta) && !isLoopDelayNeeded()) {
62-
executedCount++;
63-
64-
if (Math.abs(step * executedCount) > Math.abs(toValue - fromValue)) {
60+
if (!(controlVariable.getValue() instanceof Double)
61+
|| (step > 0 && (double) controlVariable.getValue() >= toValue)
62+
|| (step < 0 && (double) controlVariable.getValue() <= toValue)) {
6563
return true;
6664
}
67-
65+
changeControlVariable(step);
6866
isCurrentLoopInitialized = false;
6967
action.restart();
7068
}
@@ -75,7 +73,6 @@ public boolean delegate(float delta) {
7573
public void restart() {
7674
isCurrentLoopInitialized = false;
7775
isRepeatActionInitialized = false;
78-
executedCount = 0;
7976
super.restart();
8077
}
8178

@@ -101,6 +98,7 @@ private boolean interpretParameters() {
10198
Double toInterpretation = to == null ? Double.valueOf(0d) : to.interpretDouble(scope);
10299
toValue = toInterpretation.intValue();
103100
setStepValue();
101+
setControlVariable(fromValue);
104102
return true;
105103
} catch (InterpretationException interpretationException) {
106104
Log.d(getClass().getSimpleName(), "Formula interpretation for this specific Brick failed.", interpretationException);
@@ -115,4 +113,8 @@ private void setStepValue() {
115113
private void setControlVariable(int value) {
116114
controlVariable.setValue((double) value);
117115
}
116+
117+
private void changeControlVariable(int value) {
118+
controlVariable.setValue((double) controlVariable.getValue() + (double) value);
119+
}
118120
}

0 commit comments

Comments
 (0)