How do you manage state?

Managing the state of an application/game/system is critical in providing a seamless experience. With that said, how do you manage your game state? My current solution has been folders of ValueBases (attributes would be the alternative in future projects) located in ReplicatedStorage and using numerous .Changed events on those values, scattered throughout the code. This goes for the player state as well, using numerous ValueBases inside folders located in the Player. This makes reading the code much more difficult, with no central point to debug around my game state other than me poking around my explorer tree to see the current values (which doesn’t help me point to where I use this state).

While my current solution works and allows me to create a game, it just feels unorganized. I’d like to use a design/pattern where state management is simple and easy to control. So, how do you manage your game state?

1 Like

In the past I have rolled pure Lua solutions with custom replication to keep state tables synchronized, but since attributes were announced in beta I have switched to using them and things feel significantly better.

For any stateful instance I add a configuration to it called “State” and update it with attributes throughout each play session. This makes it really easy to identify which objects have a state and to view that state if I need to.

2 Likes

I’ve started using Rodux almost exclusively, and it’s fantastic for games with a ton of other systems that need to get one another’s data. It concentrates everything into one spot and makes it simple to detect changes to the store. I’ve also added a couple proprietary modules to it to make it a more complete solution (Replication middleware to replicate state changes to the client, and a BindToValueChanged function on stores to limit how many times functions are called) and it’s been working great.

I do intend to make my additions open-source at some point, and I also have a tutorial in the works, so I’ll update this when that’s out.

2 Likes

For quick and simple works (such as personal plugins) I like to use a lightweight and basic solution that requires next to no effort to use. This system by csqrl is really handy and easy to pick up.

1 Like

Roblox’s data model is my source of truth for almost anything shared between the client and server. This requires a lot of things, including attributes, value objects, binders, and reactive programming libraries.

3 Likes