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

2025/12/6

How would i go about making an upgrade that is continuous?

Just_a_person847 Just_a_person847

2025/12/6

#
I am trying to make a roguelike in greenfoot, but I need to be able to make upgrades last between stages. Whenever the world changes, how do i make the upgrade *not* reset?
danpost danpost

2025/12/7

#
Just_a_person847 wrote...
Whenever the world changes, how do i make the upgrade *not* reset?
My suggestion is to use static fields for the upgrades. They must be initialized during your initial world constructor only. Static fields are "class fields" which do not reset when a new world is created, nor when the scenario is reset. This is why they need initialized in the initial world constructor. The keyword "static" is added to the field declaration line. For example:
public static java.util.List<Upgrade> upgrades;

public MyWorld() {
    super(600, 400, 1);
    upgrades = new java.util.ArrayList<Upgrade>();
    // etc.
}
You need to login to post a reply.