This site requires JavaScript, please enable it in your browser!
Greenfoot back
dmac28
dmac28 wrote ...

2018/10/30

Why am I getting an error in my for-loop in my createStars method?

dmac28 dmac28

2018/10/30

#
public void createStars(int number)
    {
      GreenfootImage background = new getBackground
      for (int i = 0; i < number; i++)
      {
           int x = Greenfoot.getRandomNumber(getWidth());
           int y = Greenfoot.getRandomNumber(getHeight());
           int color = 120 - Greenfoot.getRandomNumber(100);
           background.setColor(new Color(color,color,color));
           background.fillOval(x, y, 2, 2);
           addObject(new Asteroid(),x,y);
      }
      }
dmac28 dmac28

2018/10/30

#
We are having a quiz this week and I am not sure why I am having errors in the parameter of my method. If anyone could help me, I would appreciate it.
danpost danpost

2018/10/30

#
dmac28 wrote...
We are having a quiz this week and I am not sure why I am having errors in the parameter of my method. If anyone could help me, I would appreciate it.
The error is in the previous line (line 3). It just "runs" into the next line because the compiler is trying to make sense of line 3 (which is not a completed line of code). Why are you adding asteroids into the world in a method that is to create stars?
You need to login to post a reply.