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

2012/7/3

One Object does not reach the other?

Bytelord Bytelord

2012/7/3

#
I'm working on my newest project and one warrior must reach the takedamage method from the enemy warrior. So basically one object must just reach the method from another. But when i am decompiling Greenfoot says:
Cannot find symbol - method takedmg()
I know this is normally easy but this problem trolls me for a hour now! Here is the code of the Warrior who wants to reach the method.
if(infight())
        {
            
           Actor enemy =   getOneObjectAtOffset(2,0,RightWarrior.class);
           enemy.takedmg();
        }
And here the method in the class of the other warrior:
public void takedmg()
    {
        System.out.println("Method reached");
    }
Please help !
erdelf erdelf

2012/7/3

#
I think changing this:
Actor enemy =   getOneObjectAtOffset(2,0,RightWarrior.class);
to this:
RightWarior enemy =  getOneObjectAtOffset(2,0,RightWarrior.class);
should be enough
Bytelord Bytelord

2012/7/3

#
I tried but it does not work, because getOneObjectAtOffset returns an actor, but thanks for you help! Anyone other suggestions?
erdelf erdelf

2012/7/3

#
oh try that:
RightWarior enemy =  (RightWarrior) getOneObjectAtOffset(2,0,RightWarrior.class);  
Bytelord Bytelord

2012/7/3

#
This finally works! Thanks A LOT
You need to login to post a reply.