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

2014/3/1

Passing score to the next world?

Marky3100 Marky3100

2014/3/1

#
Anyone who got an idea on how to do this? I shared my game here; http://www.greenfoot.org/scenarios/10980
danpost danpost

2014/3/1

#
The easiest way to pass the score is to make a reference to the new world when you create it; then set the counter in the new world to the value of the counter in the current world. This would be for going to level 2:
public void nextLevel2()
{
    if (getWorld().getObjects(Diamond.class).isEmpty() && canSee(Keyhole.class))
    {
        Mollenworld2 mw2 = new Mollenworld2();
        Counter mw1counter = (Counter)getWorld().getObjects(Counter.class).get(0);
        Counter mw2counter = (Counter)mw2.getObjects(Counter.class).get(0);
        mw2counter.setValue(mw1counter.getValue());
        Greenfoot.setWorld(mw2);
    }
}
Line 5: creates and gets ref to new world Line 6: gets ref to current world counter Line 7: gets ref to new world counter Line 8: passes the value of counter in this world to the one in the new world Line 9: sets the new world active
You need to login to post a reply.