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

2023/12/5

How to keep track of a single int across multiple objects

Silvermidnight8 Silvermidnight8

2023/12/5

#
I'm pretty new to Greenfoot and this is my first attempt at making a game . . . forgive me if this is a silly question. I'm working on a clicker game and want to track a player's score across multiple objects, if possible. For example, the upgrade object would affect the score shown in the score object when an upgrade is bought, and if there is an achievement earned, the number the score object displays would increase. I learned how to do this in block coding, but I can't figure out how to do this in Greenfoot with Javascript. Is there a solution to this?
danpost danpost

2023/12/5

#
Silvermidnight8 wrote...
How to keep track of a single int across multiple objects
Easiest reply would be to put the int in your World subclass where it will be accessible to all Actor objects in the active world. You could go as far as adding a getter and a setter method (for that int) in that World subclass as well.
You need to login to post a reply.