@@ -40,7 +40,6 @@ public class ForVariableFromToAction extends LoopAction {
40
40
private boolean isRepeatActionInitialized = false ;
41
41
private int fromValue ;
42
42
private int toValue ;
43
- private int executedCount = 0 ;
44
43
private int step = 1 ;
45
44
46
45
@ Override
@@ -55,16 +54,15 @@ public boolean delegate(float delta) {
55
54
isCurrentLoopInitialized = true ;
56
55
}
57
56
58
- setControlVariable (fromValue + step * executedCount );
59
57
setCurrentTime (getCurrentTime () + delta );
60
58
61
59
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 )) {
65
63
return true ;
66
64
}
67
-
65
+ changeControlVariable ( step );
68
66
isCurrentLoopInitialized = false ;
69
67
action .restart ();
70
68
}
@@ -75,7 +73,6 @@ public boolean delegate(float delta) {
75
73
public void restart () {
76
74
isCurrentLoopInitialized = false ;
77
75
isRepeatActionInitialized = false ;
78
- executedCount = 0 ;
79
76
super .restart ();
80
77
}
81
78
@@ -101,6 +98,7 @@ private boolean interpretParameters() {
101
98
Double toInterpretation = to == null ? Double .valueOf (0d ) : to .interpretDouble (scope );
102
99
toValue = toInterpretation .intValue ();
103
100
setStepValue ();
101
+ setControlVariable (fromValue );
104
102
return true ;
105
103
} catch (InterpretationException interpretationException ) {
106
104
Log .d (getClass ().getSimpleName (), "Formula interpretation for this specific Brick failed." , interpretationException );
@@ -115,4 +113,8 @@ private void setStepValue() {
115
113
private void setControlVariable (int value ) {
116
114
controlVariable .setValue ((double ) value );
117
115
}
116
+
117
+ private void changeControlVariable (int value ) {
118
+ controlVariable .setValue ((double ) controlVariable .getValue () + (double ) value );
119
+ }
118
120
}
0 commit comments