1
float speed = 1;
void setup() {
size(400, 300);
}

void draw() {
background(255);
move();
display(); 
}

void move() {
x = x + speed;
if (x > 350) {
speed = 0;
}
}

void display(x,y) {
fill(#FF2121);
translate(x,y);
ellipse(0, 0, 60, 60);
rect(-10, 15, 20, 100);
}  

Unexpected token: x on "Void display (x,y)" Basically this program moves the ellipse and rect to other side of the window. is this the right way to do it? or is there any other easy way.

Example 0 = ellipse [] = rect

move to other side of window (speed of 1) and when it hit the edge, both them stop.

1 Answer 1

2

Parameters need types, just like variables do.

void display(float x, float y) {

Also note that since your display() function takes 2 parameters, it's illegal to call it without any parameters, which is what you're doing in your draw() function.

Also note that you've never defined the x variable, so that's another error.

Please get into the habit of working in smaller chunks instead of trying to write your whole program all at one time. You've got quite a few errors here, and it's going to be hard to fix one without fixing the others. I recommend starting over with something simpler, and only moving forward when you have something that works.

Sign up to request clarification or add additional context in comments.

4 Comments

i did that before posting here but on draw function, "display()" shows error.
@DipakMukesh You display(float x, float y) function takes two parameters. Calling display() without any parameters is an error.
Thanks sorted, if you can give a tip when blocks hit the edge, how can i send it back to beginning position?
@DipakMukesh Please see this tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.