Use a variable from another state ? #2360
-
Hey ! I need some help with my code. I'm trying to make a shop using a Can I get help on this ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Might be helpful to look at some code but you have several options here: 1 - Make the boolean from the other state public so you can access it in another class I personally use the second option for most of my games. |
Beta Was this translation helpful? Give feedback.
Might be helpful to look at some code but you have several options here:
1 - Make the boolean from the other state public so you can access it in another class
2 - Create a singleton and add the information you want to share between states in there so different states can access it
3 - Put the info you want to share in the games save state and when you load the game pass the loaded saved data into each state
4 - Create a public function that will return the boolean value and call it in another class
I personally use the second option for most of my games.