# Confusion on classes and objects

**URL:** <https://discourse.processing.org/t/confusion-on-classes-and-objects/22838>\
**Category:** Coding Questions\
**Created:** [July 25, 2020, 10:16pm UTC](https://discourse.processing.org/t/confusion-on-classes-and-objects/22838 "2020-07-25T22:16:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edgard142ofWelshdale](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@Edgard142ofWelshdale](https://discourse.processing.org/u/Edgard142ofWelshdale)\
**Post date:** [July 25, 2020, 10:16pm UTC](https://discourse.processing.org/t/confusion-on-classes-and-objects/22838/1 "2020-07-25T22:16:31Z")

</div>

Hello! I just started using classes in my processing games(as in, this is my first attempt). I am incredibly lost as to how to do it correctly. I looked at the processing 3 language reference and it doesn’t have much on classes.

In my head, the following code should work to create an enemy that moves around the screen as a red rectangle. However, when I press run, all the variable declarations for enemy(E1.x = 57; and so on) get an error and say I should consider adding variabledeclaratorId. I could find nothing on this on the internet and so I assume it is simply a poorly worded error message. Could someone please fix this, and help me find references for classes in processing? The syntax and where to put the statements(setup, draw, or in-between?) has me lost.

```auto
void setup()
{
   size(200, 200);
}

Enemy E1 = new Enemy;
E1.x = 57;//x position
E1.y = 98;//y position
E1.w = 20;//width
E1.h = 30;//height
E1.speedX = 7;
E1.speedY = -12;

void draw()
{
   background(0);

   //update enemy position
   E1.x += E1.speedX;
   E1.y += E1.speedY;

   fill(255, 0, 0);
   rect(E1.x, E1.y, E1.w, E1.h);//draw enemy
}

class Enemy
{
   int x, y, speedX, speedY, w, h;
}

```

---

<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:** [July 26, 2020, 12:36am UTC](https://discourse.processing.org/t/confusion-on-classes-and-objects/22838/2 "2020-07-26T00:36:32Z")

</div>

Welcome to the forum.

> [@Edgard142ofWelshdale](#):
>
> I looked at the processing 3 language reference and it doesn’t have much on classes.

One of the best tools in a programmers tool chest is knowing the resources available to you and learning to navigate, filter and use them.

This is a very short list:

> **Resources \< Click here to expand !**
>
> I encourage you to review the resources available here:
> 
> - The Processing _website_ has references, examples, tutorials, etc.  
> [https://processing.org/](https://processing.org/)
> - The Processing PDE (IDE) has lots to offer!  
> An exploration of the tabs will reveal what is available; libraries, tools and local examples there.
> - The Coding Train  
> [https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> - Happy Coding  
> [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)
> - The source code can give insight if you are adventurous:  
> [GitHub - processing/processing: Source code for the Processing Core and Development Environment (PDE)](https://github.com/processing/processing)  
> Many of the Processing functions are here:  
> [processing/core/src/processing/core/PApplet.java at master · processing/processing · GitHub](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java)
> - The Processing Foundation  
> [https://processingfoundation.org/](https://processingfoundation.org/)  
> Check out the tabs.  
> In the education tab, there is a reference to the Coding Train.
> - And the Internet. `:)`

Check out the Processing _tutorials_ and the Coding Train.

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

There is also the Java documentation:

> **[Lesson: Classes and Objects (The Java™ Tutorials \> Learning the Java...](https://docs.oracle.com/javase/tutorial/java/javaOO/index.html)**
>
> This beginner Java tutorial describes fundamentals of programming in the Java programming language

`:)`

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [July 26, 2020, 1:03am UTC](https://discourse.processing.org/t/confusion-on-classes-and-objects/22838/3 "2020-07-26T01:03:43Z")

</div>

https://www.youtube.com/embed/videoseries?list=PLRqwX-V7Uu6bb7z2IJaTlzwzIg_5yvL4i&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1

Hello @Edgard142ofWelshdale

This playlist will give you a good foundation in classes and objects.

🤓
