Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CATROID-1462 Change variable by "" brick does not work #4685

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -75,7 +73,6 @@ public boolean delegate(float delta) {
public void restart() {
isCurrentLoopInitialized = false;
isRepeatActionInitialized = false;
executedCount = 0;
super.restart();
}

Expand All @@ -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);
Expand All @@ -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);
}
}