Closed Frozenfire92 closed 1 month ago
I think it makes sense to be able to read the expression properties back from the state chart and it's easy enough to add, so I'm going to add this.
However setting an expression property is considerably more expensive than just storing a value in a custom variable. This is because whenever you change an expression property the state chart will check all currently active automatic transitions (which may use guards based on the expression properties). So I wouldn't recommend using this as a general purpose storage container but rather only store expression properties that your guards will actually use.
However setting an expression property is considerably more expensive than just storing a value in a custom variable.
Fair point. This kind of gives me two thoughts
set_state_property
that doesn't affect transitions
set_expression_property_no_update
to allow bypassing of the transition checks
My game likely doesn't have the performance needs, but I think to get myself into a better habit I will instead store my own custom dictionary/variables
If you just need a general-purpose storage area for key-value pairs - every godot object has set_meta
/ get_meta
.
It would be nice to have an interface to get expression properties. Currently it seems like the state chart uses this solely for expression based guards, however I think it could also be useful for "temporary data related to states" that aren't necessarily used by guards. This has the benefit of not needing additional variables to be stored in your main script, as well as being able to debug it for free in the state chart debug window
Imagine the scenario of a game where a player can select a card from a hand. The states could be
Selectable
andSelected
. There are transitions for the events"card_selected"
and"card_placed"
to go between them. During the Selected state the game displays a "preview card" based on the index/data of the card in the hand. You could store this as acurrentSelectedCard
variable, but why not part of the state chart (as it is state)Today
and then access it like so
and then clear it like so
Proposal
it could be more ergonomic if the state chart exposed these functions