It works!
Thank you so very much @danpost :D
while (i < stars) {
int x = Greenfoot.getRandomNumber(getWidth());
int y = Greenfoot.getRandomNumber(getHeight());
addObject(new Star(), x, y);
i++;
}private Stars[] stars; // before the while loop: stars = new Stars[stars]; // in the while loop: int x = .... int y = .... Star s = new Star(); addObject(s, x, y); stars[i] = s; i++;
public class Space extends World
{
int stars = 100;
int i;
private Stars[] stars;
private void createStars()
{
stars = new Stars[stars];
while (i < stars) {
int x = Greenfoot.getRandomNumber(getWidth());
int y = Greenfoot.getRandomNumber(getHeight());
Star s = new Star();
addObject(s, x, y);
stars[i] = s;
i++;
}
}
private Star[] star;
star = new Star[star];
// the 'opposite' of x = (x + 1) % getWorld().getWidth(); // would be x = (x - 1 + getWorld().getWidth()) % getWorld().getWidth();