# Can't run code due to syntax errors

**URL:** <https://discourse.processing.org/t/cant-run-code-due-to-syntax-errors/32193>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [September 11, 2021, 12:22am UTC](https://discourse.processing.org/t/cant-run-code-due-to-syntax-errors/32193 "2021-09-11T00:22:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mayyu](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mayyu](https://discourse.processing.org/u/mayyu)\
**Post date:** [September 11, 2021, 12:22am UTC](https://discourse.processing.org/t/cant-run-code-due-to-syntax-errors/32193/1 "2021-09-11T00:22:16Z")

</div>

\<  
public class Person{  
float x;  
float y;  
float xspeed;  
float yspeed;

}  
Person (float tempX, float tempY) {  
x=tempX;  
y=tempY;  
xspeed = 4;  
yspeed = 4;  
}

void move() {  
x = x+xspeed;  
if (x\>1000||x\<0){  
xspeed= -xspeed;  
}  
if (mousePressed){  
y=y+yspeed;  
if (y\<0||y\>1000){  
yspeed = -yspeed;  
}  
}

}  
void display(){  
fill(100,50,300);  
circle(x,y,50);  
line(x, y+25, x, y+100);  
line (x, y+100, x-20, y +120);  
line (x, y+100, x+20, y+120);  
line (x-40, y+50, x+40, y+50);  
}  
void settings (){  
size(1000, 1000);  
}  
ArrayList people;  
void setup(){  
size(1000,1000)  
people = new ArrayList();  
people.add (new Person(500,400));  
}  
void draw(){  
background (150,350,200);  
for (int i = people.size()1; i \>=0;i++){  
Person person = people.get(i);  
person.move();  
person.display();  
}  
}  
voice keyPressed(){  
if (key==" "){  
people.add(new Person(x,y,));  
}  
}

> 

please help I have no idea what I’m doing I’m just trying to make a guy populate everytime you press the space bar. i was following the examples on the processing site but for some reason its not working please tell me why.

---

<div class="post-metadata">

**Author:** ![mayyu](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mayyu](https://discourse.processing.org/u/mayyu)\
**Post date:** [September 11, 2021, 12:24am UTC](https://discourse.processing.org/t/cant-run-code-due-to-syntax-errors/32193/2 "2021-09-11T00:24:16Z")

</div>

it also says im mixing active and static modes and i dont know what that means

---

<div class="post-metadata">

**Author:** ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)\
**Post date:** [September 11, 2021, 12:40am UTC](https://discourse.processing.org/t/cant-run-code-due-to-syntax-errors/32193/3 "2021-09-11T00:40:37Z")

</div>

at a glance your “Person” class constructor and methods are outside of its scope. to begin with you can change it to this and work from there.

```auto
class Person{
    float x;
    float y;
    float xspeed;
    float yspeed;

    Person (float tempX, float tempY) {
        x=tempX;
        y=tempY;
        xspeed = 4;
        yspeed = 4;
    }

    void move() {
        x = x+xspeed;
        if (x>1000||x<0){
            xspeed= -xspeed;
        }
        if (mousePressed){
            y=y+yspeed;
        }
        if (y<0||y>1000){
            yspeed = -yspeed;
        }
    }

    void display(){
        fill(100,50,300);
        circle(x,y,50);
        line(x, y+25, x, y+100);
        line (x, y+100, x-20, y +120);
        line (x, y+100, x+20, y+120);
        line (x-40, y+50, x+40, y+50);
    }
}

```

_note: the move method of the person class will probably need work too._

the debugger should tell you everything you need to know just start at the beginning and work your way through. You have open/closing brace issues and one of your methods is defined with “voice” type which should be void.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 11, 2021, 9:32am UTC](https://discourse.processing.org/t/cant-run-code-due-to-syntax-errors/32193/4 "2021-09-11T09:32:57Z")

</div>

Hello,

Please post formatted code as a courtesy to everyone:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

> [@mayyu](#):
>
> please help I have no idea what I’m doing

A good place to start!

I will help you help yourself.

There are resources here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

Start with small working code and build on that.  
Comment your code.  
Save each working version with comments… you can add number to the saved versions.

Tutorial:

> **[Objects](https://processing.org/tutorials/objects/)**
>
> The basics of object-oriented programming.

Example:

> **[ArrayList of objects / Examples](https://processing.org/examples/arraylistclass.html)**
>
> This example demonstrates how to use a Java ArrayList to store a variable number of objects. Items can be added and removed from the ArrayList. Click the mouse to add bouncing balls.

In the Processing IDE you should see the errors:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a529b345244b77502000d8e29b9a0071b22601d9.png)

Move your mouse over the red underlined errors.

Look up the references.  
The `keywords` (usually highlighted) such as `key` have references; a right mouse press over a keyword may also give you options to “`Find in Reference`”.  
`x` and `y` are underlined… what error shows up?

There are other errors in your code.  
You can work on them one at a time.

Since this is homework your growth and development as a programmer means an investment of work on your part.

Enjoy the growing pains… you come out stronger in the end!

I did manage to correct the code and get this out of it:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/835e77e9f69967ccba8cce915f390cb7833cf698.png)

`:)`
