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

2017/12/5

trying to access a counter from MyWorld in Actor class

ryan22 ryan22

2017/12/5

#
if(getOneIntersectingObject(PlusTen.class) != null){
            getWorld().score = MyWorld.getWorld().score + 10;
            removeTouching(PlusTen.class);
            Greenfoot.playSound("Woohoo.mp3");
        }
        if(getOneIntersectingObject(MinusTen.class) != null){
            MinusTen mt = new MinusTen();
            MyWorld.getWorld().score = ((MyWorld)getWorld()).score - 10;
            removeTouching(MinusTen.class);
            Greenfoot.playSound("Doh.wav");
        }
Can someone fix this for me... Thanks!
ryan22 ryan22

2017/12/5

#
Sorry forgot to say that the error was that I could call the counter 'score' from MyWorld. I can't find the documentation necessary for it.
danpost danpost

2017/12/5

#
Of the four places you try to access the Score object, the last is most likely to work. Change the other three to match it. Why are you creating another MinusTen object at line 7?
ryan22 ryan22

2017/12/5

#
Thanks. The Minus and Plus Ten are just object in the game where if you hit one, you lose or gain points based on it.
danpost danpost

2017/12/5

#
ryan22 wrote...
The Minus and Plus Ten are just object in the game where if you hit one, you lose or gain points based on it.
I understood that. I was just wondering why you would create one for no reason at line 7 above.
You need to login to post a reply.