Processing: Tweak mode together with switch() causes error

Created on 13 Jun 2020  路  4Comments  路  Source: processing/processing



Description



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.

Steps to Reproduce


  1. run the following code in tweak mode:
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;
  }
}

Your Environment



  • Processing version: 3.5.4
  • Operating System and OS version: tested on macOS 10.15.4 and Windows 10 Version 1909
  • Other information:

Most helpful comment

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.

All 4 comments

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;
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

PaulDance picture PaulDance  路  3Comments

tegacodes picture tegacodes  路  6Comments

GoldenQubicle picture GoldenQubicle  路  8Comments

sucrecacao picture sucrecacao  路  5Comments

fxmech picture fxmech  路  4Comments