My request is a way to use the random number generator once at the beginning of the code. Currently I am trying to make an ant spawn at the antpile (this works) the go to a random point (works) then go back to the antpile(doesn't work) and delete itself(haven't got there yet) (unless it hits a food source.) I have a problem because I'm trying to create a random point for it to go to but it keeps randomly generating places for it to go to (in which it will spaz out.) I want it to go to a singular random point the go back the the antpile where it started at. If I create time and on the 2nd time step it creates the point for it go to I don't know how to make it remember when to stop and go back. Here is my code:
import greenfoot.*;
public class Ant extends Actor
{int time=0;
public void act()
{
time=time+1;
move(4);
if(time==1)
{
int x=Greenfoot.getRandomNumber(599);
int y=Greenfoot.getRandomNumber(399);
turnTowards(x,y);
}
//if(isAtEdge())
//{
//this doesn't work and I won't need it if my problem is solved
//turnTowards(Antpile.getX(),Antpile.getY());
//}
}
}
