Posted February 12, 2020 by Pixelated Pope
A new version of TrueState is now available!
While the overall system functions largely the same, there were enough changes under the hood to necessitate a major version. Specifically many of the built in variables have been renamed or removed to reduce collisions with common variable names (such as "state"). As such, I don't recommend "upgrading" your existing project from TrueState v1 to v2.
Let's talk about some of the changes and new features.
Previously the state script template was an if/else for the step event and the draw event. And while a similar setup will still work, I've added 2 more possible sections that are very useful. So now that there are 4 possibilities, the state script template now uses a switch statement:
The TRUESTATE_NEW section replaces the old "state_new" variable. Any code you would have put inside an "if(state_new)" check can now just go into the TRUESTATE_NEW block. It will also run more reliably than putting the check in the step block. Some users may have ran into issues where the draw event would run before the step event because of when an instance was created. This would cause issues as the draw event may have been expecting values set in the state new block. TRUESTATE_NEW will run reliably before any other state code.
TRUESTATE_FINAL is a new section that will be ran right before switching to a new state and when an instance is destroyed or cleaned up. This allows you to set variables or create structures in NEW and set them back or clean them up in FINAL. It won't be necessary for all states, and can be omitted from your switch statement if you aren't using it.
In 1.0, state_var was an array that was intended to be used for variables that only a single state really cared about. The issue with this is that, as it was an array, you had to use number indexes and comments to keep track of everything. It wasn't great for code clarity. Now truestate_vars is a ds_map, so you can use a string with a map accessor to read and update the value.
In 1.0, there was an event script called "truestate_draw_gui_end" that was intended to go into the draw gui end event. This was not ideal for many reasons (including that it wouldn't run if your instance's visible property was set to false), and I decided to correct that in 2.0. The same functionality is now ran in the begin step event, so the related script has been renamed, and some logic has been reworked so that state switching and updating now happens in the begin step event instead of after all other events.
Again, this isn't an earth shattering change, but hopefully you'll appreciate the new features and general stability improvements.