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


I need help writing some code....

MakerOfGames MakerOfGames


Lets say there are 2 actors. Actor 1 and Actor 2. And lets give them a variable, Actor 1 is A and Actor 2 is B. So....there is a boolean, its called is false. if (detectB= false, look forB in a certain radius . if a B is in a certain radius, detectB=true how would you make a code like that?
IsVarious IsVarious


I'll write some of this as pusedo code, but you're wanting a basic if statement.
private int ActorA = 0;
private int ActorB = 0
private boolean Detect_B = false;

// some method to store the if statement
public void DetectActorB()
    If (!DetectB){
    } else {
             Detect_B = true;
// The method that looks for Actor B in a certain raidus
public void  LookForActorBInRadius() 
     Here you would put the code that detects another actor/object within a given radius. 
I would start with code like this, and try to work through it part by part. If you just copy and paste it, It will not work. You'll have to do some research here to find out the exact code you need to detect an object/actor in a certain radius. Good luck
You need to login to post a reply.