Running sketch in tweak mode with the switch() statement somewhere in code causes this error: "case expressions must be constant expressions". Running normally (without tweak mode) works without problems.
void setup() {
size(200, 200);
}
void draw() {
background(255);
int i = 2;
switch(i){
case 1: circle(100, 100, 20);
break;
case 2: rect(100, 100, 20, 20);
break;
}
}
Are any sketches working in Tweak mode for you?
The issue here is Tweak mode trying to convert case 1: into case <variable>: so it breaks the case statement.
A fix should be added to https://github.com/processing/processing/blob/master/java/src/processing/mode/java/tweak/SketchParser.java to ignore case statements.
Meanwhile, as a workaround, you can enable tweaking only specific lines by adding the comment:
/// tweak
at the end of each line you wish to tweak. When adding such comment, Tweak mode will ignore the rest of the values in the sketch.
Seems like that might be handled as a special case in SketchParser.addAllDecimalNumbers()
Meanwhile, as a workaround, you can enable tweaking only specific lines by adding the comment:
/// tweak
I can confirm that the workaround works. (It requires that you separate the case statement from its first line.)
void setup() {
size(200, 200);
}
void draw() {
background(255); /// tweak
int i = 2;
switch(i) {
case 1:
circle(100, 100, 20); /// tweak
break;
case 2:
rect(100, 100, 20, 20); /// tweak
break;
}
}
Most helpful comment
The issue here is Tweak mode trying to convert
case 1:intocase <variable>:so it breaks the case statement.A fix should be added to https://github.com/processing/processing/blob/master/java/src/processing/mode/java/tweak/SketchParser.java to ignore case statements.
Meanwhile, as a workaround, you can enable tweaking only specific lines by adding the comment:
/// tweakat the end of each line you wish to tweak. When adding such comment, Tweak mode will ignore the rest of the values in the sketch.