If statement in arrays

So I am making a prototype for my game to try and demonstrate what I am trying to do.


In the editor, you can see only one circle moves but I want all the circles to move. This is probably the wrong way to do things but its the way I came up with, so can someone help me out.

I have made an improvement to the code but i still am having the same problem



Welcome to the forum! :wink:

Pro tip : in the p5 web editor you can auto format your code by going into Edit → Tidy Code

Your code doesn’t work because when you are calling in the draw() function :

for (let i = 0; i < 3; i++) {

Then as soon as the round variable has the value 100, you start checking the bubbles[0] object in the array and it’s calling its move() method :

move() {
  if (round == 100) {
    this.x = random(24, 376);
    this.y = random(24, 376);
    round = 0;

But here the condition is true and the round variable gets reset to 0 so when you are trying to move the next circle it’s no more 100 and it only moves the first circle!!

What you can use is the frameCount variable that is counting the number of frames since the beginning of the sketch and it’s exactly what you are doing! :yum:

1 Like

thank you so much it now works great!!