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

2014/1/5

If statements with multiple actors

Ushi1 Ushi1

2014/1/5

#
    public void startChasingForBankVan()
    {

        if((RobbersRetreat)canSee(MoneyBag.class))
        {
            move();
            faceBaddies();
        }
    }
i have problem with the if statement here i want the bank van to move if the moneybags are touching the robbersretreat my canSee method and face Badddies method (courtesy of danpost) work fine
danpost danpost

2014/1/5

#
If this code is in the 'RobbersRetreat' class, then just remove '(RobbersRetreat)' from line 4.
Ushi1 Ushi1

2014/1/5

#
it is in the BankVan class. Is it still possible, or is there a way to move all of this to the RobbersRetreat class but still with the BankVan moving - not the RobbersRetreat
danpost danpost

2014/1/5

#
Presuming that you always have one RobbersRetreat in the world:
if ( (RobbersRetreat)getWorld().getObjects(RobbersRetreat.class).get(0) ).canSee(MoneyBag.class)
You need to login to post a reply.