Skip to content

Use a variable from another state ? #2360

Answered by RichardBray
NalegFR asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@NalegFR
Comment options

@RichardBray
Comment options

Answer selected by NalegFR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants