So i've been trying to make a game using a state machine/state pattern and im having trouble. So I have each state in its own class being managed by a state machine class (which is inherited by any class that needs multiple states). I've read many examples and tutorials on state machines but none of them seem to explain how the states communicate and share data.
I'l give some hypothetical game situations. What if, when playing an rpg you're in the "gameplay state" and you hit "M" to change to a "map view state", the map state is giong to need to know the players position in the world. What if you're in a "menu state" and change the games difficulty, then the "gampley state" would also need to know the new difficulty setting. If you're in an "inventory state" and you equip items then the "gameplay state" would need to know so it can display these new items on the player.
I dont know where this data should be stored and how it should be shared. If anyone knows a solution i would realy appreciate it.