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

2014/11/18

How to create an object that is storing variables throughout different levels

nickthequik nickthequik

2014/11/18

#
So I created a Variables class that is neither a World or Actor subclass, but rather is just one of the "Other Classes" Now I want to know how to create this object once and have it stay in memory so that it can be accessed throughout the game constantly. I am going to use it to keep track of whether the player has bought certain items from a store so that the player cannot buy the same item twice. Any help appreciated, nickthequik
danpost danpost

2014/11/18

#
You can create the object pretty much anywhere; however, the best place would be in your world constructor. Use a 'static' field in the class to hold a reference to the object. Then, from anywhere, you can use 'ClassNameFieldIsIn.fieldName' to access it.
You need to login to post a reply.