Expecting TRIPLE_DOT, found 'tempId' And Other Things
in
Programming Questions
•
10 months ago
Hi, I'm a new programmer, and I had a question about some errors I had with this sketch. I've just been experimenting with arrays and class files over the last few days, and am new to some of the syntax. In this program, I'm trying to get a series of rectangles acting as buttons to switch colors when they're pressed using arrays, just to use as a template for some more advanced code. It's not done yet, as I tested it out to see if it would work, got an Expecting TRIPLE_DOT error, and decided that I would fix this bug as well as get some feedback on how to make it better/fix other things before moving on. I looked up the TRIPLE_DOT error, and also tried to find syntax for declaring a single value for an int array inside a constructor online, but found nothing that was helpful/noob friendly.
Anyways, here's my code for the main file:
- int i;
- int j;
- int numButtonX;
- int numButtonY;
- Button [][] newButton;
- boolean [][] on;
- void setup() {
- size(500,500);
- numButtonX = width/50;
- numButtonY = height/50;
- newButton = new Button[numButtonX][numButtonY];
- on = new boolean[numButtonX][numButtonY];
- for(i=0;i<numButtonX;i++) {
- for(j=0;j<numButtonY;j++) {
- newButton[i][j] = new Button(i,j,i*50,j*50);
- on[i][j] = false;
- }
- }
- }
- void draw() {
- for(i=0;i<numButtonX;i++) {
- for(j=0;j<numButtonY;j++) {
- newButton.display();
- }
- }
- }
- void mousePressed() {
- for(i=0;i<numButtonX;i++) {
- for(j=0;j<numButtonY;j++) {
- on[i][j] = false;
- }
- }
- on[round(mouseX/50)][round(mouseY/50)] = true;
- }
- class Button {
- int [] id = new int [2];
- int x;
- int y;
- int w = 45;
- int h = 45;
- Button(int tempId[0], int tempId[1], int tempX, int tempY) {
- id[0] = tempId[0];
- id[1] = tempId[1];
- x = tempX;
- y = tempY;
- }
- void display() {
- if(on[id[0]][id[1]]) {
- fill(255);
- rect(x,y,w,h);
- }
- else if(!on[id[0]][id[1]]) {
- fill(100);
- rect(x,y,w,h);
- }
- }
- }
1