Hi, I kinda know how to program many different things so one of my friends asked me to make an easy game for him that is supposed to measure the reaction time. I made a chance system which is a little complicated but now that I have finished it I started the game just to find an error message coming up when the "GreenCar" reaches the end of the world even though it is just supposed to respawn... it tells me the problem is the spawning part but I don't see the problem so could you guys help me out? Thanks!
Here are the codes for the "GreenCar" class which is the one with errors:
int Space = 10;
int AmountChance = 10;
int Amount = 10;
/**
* Act - do whatever the GreenCar wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(15);
if (atWorldEdge())
{
getWorld().removeObject(this);
Space = Greenfoot.getRandomNumber(5);
}
if (Space==1)
{
AmountChance = Greenfoot.getRandomNumber(3);
getWorld().addObject(new GreenCar(), 50, 350);
return;
}
if (Space==2)
{
AmountChance = Greenfoot.getRandomNumber(3);
getWorld().addObject(new GreenCar(), 50, 50);
return;
}
if (Space==3)
{
AmountChance = Greenfoot.getRandomNumber(3);
getWorld().addObject(new GreenCar(), 50, 150);
return;
}
if (Space==0)
{
AmountChance = Greenfoot.getRandomNumber(3);
getWorld().addObject(new GreenCar(), 50, 450);
return;
}
if (AmountChance==2)
{
Amount = Greenfoot.getRandomNumber(6);
}
if (Amount==1)
{
getWorld().addObject(new GreenCar(), 50, 50);
return;
}
if (Amount==2)
{
getWorld().addObject(new GreenCar(), 50, 150);
return;
}
if (Amount==3)
{
getWorld().addObject(new GreenCar(), 50, 350);
return;
}
if (Amount==4)
{
getWorld().addObject(new GreenCar(), 50, 450);
return;
}
if (Amount==5)
{
getWorld().addObject(new GreenCar(), 50, 250);
return;
}
if (canSee(GreenCar.class))
{
getWorld().removeObject(this);
}
if (canSee(RedCar.class))
{
eat(RedCar.class);
}
if (canSee(BlueCar.class))
{
eat(BlueCar.class);
}
if (canSee(Car.class))
{
eat(RedCar.class);
}
}
}

