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

2016/5/5

How to Get Integers to Persist Through Worlds

Matt_Baker11 Matt_Baker11

2016/5/5

#
Hello, I have a question about how I can have integers persist through different worlds. In my game, I have my character moving between worlds, with different actors of the same character in each specific world, but I don't know how to keep my health of the character, or other integers, the same when moving to different worlds, and I was wondering if anyone could help me out. Thanks.
danpost danpost

2016/5/5

#
Matt_Baker11 wrote...
In my game, I have my character moving between worlds, with different actors of the same character in each specific world, but I don't know how to keep my health of the character, or other integers, the same when moving to different worlds
If you are passing your character between the two worlds, then any fields that it holds will come with it. You may be able to take use of the 'addedToWorld' method of the Actor class in the class of your character to have it add back in any objects that the character may have associated with it.
SPower SPower

2016/5/5

#
You could also create a separate class (one that isn't a subclass of Actor or World), and store the numbers there. This class could, for example, be called PlayerData, and each time a new world is created, it asks that class for numbers you want to pass through.
You need to login to post a reply.