unexpected token: void
in
Programming Questions
•
1 year ago
Cannot seem to figure this one out. I was having trouble with buttons so i am trying to figure them out, have been trying for 2 days and i havent moved from where i was. thanks in advance!
int x = 50;
int speed = 1;
void setup() {
size(400, 400);
}
void draw() {
background(255);
//set sllipse and rect to center
rectMode(CENTER);
ellipseMode(CENTER);
{//draw large rectangle
fill(255);
rect(200, 120, 390, 200);
}
{//draw red button
fill(255, 0, 0);
rect(50, 250, 50, 25);
}
{//draw green button
fill(0, 200, 0);
rect(150, 250, 50, 25);
}
{//draw blue button
fill(0, 0, 200);
rect(250, 250, 50, 25);
}
{//draw yellow button
fill(225, 225, 0);
rect(350, 250, 50, 25);
}
int x = 350;
int y = 250;
int w = 50;
int h = 25;
void mousePressed() {
if (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h && mousePressed) {
int speed = 1;
} else {
int speed = 0;
}
}
// Add the current speed to the x location.
x = x + speed;
if ((x > width-30) || (x < 30)) {
// If the object reaches either edge, multiply speed by -1 to turn it around.
speed = speed * -1;
}
// Display circle at x location
stroke(0);
fill(175);
ellipse(x, 110, 50, 50);
}
1