Stats Management

Here is how I handle stats on game objects in Pastel Future.

Begin Step, Step, End Step
A little GameMaker context… There are the three Step events in GameMaker 2. Begin Step fires on all objects, then Step, then End Step. The idea is that you know every object has performed its Begin Step if you are in Step. Same goes for Step and End Step.

Stats, Modifiers, and Final Calculations
This is the basic system for applying stats to an object. The part I’m not sure about, is when using this method, you have to perform all of your actions in End Step after the final calculations. I don’t think there’s anything inherently wrong with this, but you end up setting variables in Step and acting on them in End Step. You also effectively lose End Step functionality, since every action is occurring in End Step, leaving you no way to know if you are acting after all per-frame actions are complete.

We perform all of our logic in Step though. So maybe since we’re normally checking a variable set in Step to decide if we perform an action in End Step, we still make End Step work. Not sure.

Variable Names
Example variables names for Damage stat.

  • _stat_damage_base
  • _stat_damage_mod
  • _stat_damage_mult
  • _stat_damage: holds final value for use in object actions

Set base values (Begin Step)
Set the base values for all non-aggregate stats in this step. Something like Damage is set to its base value of 10 in this step. However, a stat like Miles Walked would not be set here (would be done in Create), as it is cumulative and only needs initialized once.

Stat value have three types: BASE, MOD, MULT

  • BASE: Set to the base value of a stat. In this example, base Damage is set to 10.
  • MOD: Initially, there are no modifiers applied. This is set to 0.
  • MULT: The multiplier is always applied in the final calculation, meaning a default value of 1.

Calculate Modifiers (Step)
In the Step event, all modifiers for a given stat are applied to the MOD and MULT variables. This is where items, enemies, world events, etc apply their buffs and debuffs. Let’s give the example of a player wearing gear that gives them +18 damage. The player is also buffed by a world event to have quad damage.

  • BASE: The base value, with no modifiers or multipliers.
  • MOD: This is an absolute value. In the case of +Damage: 18, MOD is increased by 18
  • MULT: This value is multiplied by the sum of the BASE value and MOD value. In the case of a buff such as Quad Damage, MOD would be set to 4.

Calculate Final Values (End Step)
The final Damage value is determined using this formula:

_stat_damage = (_stat_damage_base + _stat_damage_mod) * _stat_damage_mult

Every action we perform that requires a Damage value will use the _stat_damage variable.