Question regarding the index in MUI spells

Level 2
Joined
May 27, 2024
Messages
13
So, according to all the MUI tutorials online, you're supposed to do something like this for MUI (GUI spell example incoming):
  • Flower Power
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Mass Hook
    • Actions
      • -------- The amount of Projectiles rotating around the hero :D --------
      • Set VariableSet XF_Amount_of_Hooks = ((Level of Mass Hook for (Triggering unit)) x 3)
      • For each (Integer XF_Start) from 1 to XF_Amount_of_Hooks, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • XF_Skip Equal to 0
            • Then - Actions
              • -------- Determins the String model name ... .. so it gives the model of the projectile rotating around the hero .. and the hook --------
              • Set VariableSet XF_Model_Rotators[0] = Abilities\Weapons\SentinelMissile\SentinelMissile.mdl
              • Set VariableSet XF_Model_Rotators[1] = Abilities\Weapons\DruidoftheTalonMissile\DruidoftheTalonMissile.mdl
              • Trigger - Turn on Flower Power Loop <gen>
            • Else - Actions
          • Set VariableSet XF_Times = (XF_Times + 1)
          • Set VariableSet XF_Skip = (XF_Skip + 1)
          • Set VariableSet XF_Off[XF_Times] = True
          • Set VariableSet XF_Hero[XF_Times] = (Casting unit)
          • Set VariableSet XF_Point[8] = (Position of XF_Hero[XF_Times])
          • -------- ------------------------------------------------------------------------------------------------------------------- --------
          • -------- ------------------------------------------------------------------------------------------------------------------- --------
          • -------- The SETTINGS below this line --------
          • Set VariableSet XF_Hooks[XF_Times] = 5
          • Set VariableSet XF_Max_Dist_Decoy[XF_Times] = 550.00
          • Set VariableSet XF_Speed[XF_Times] = 12.00
          • -------- Do not touch anything below this line --------
          • -------- ------------------------------------------------------------------------------------------------------------------- --------
          • -------- ------------------------------------------------------------------------------------------------------------------- --------
          • Set VariableSet XF_Ticks[XF_Times] = (Random real number between 50.00 and 250.00)
          • Set VariableSet XF_Part[XF_Times] = 0
          • Set VariableSet XF_MaxDistance[XF_Times] = 71.00
          • Set VariableSet XF_Angle[XF_Times] = (Random angle)
          • Set VariableSet XF_Point[0] = (XF_Point[8] offset by 50.00 towards XF_Angle[XF_Times] degrees.)
          • Unit - Create 1 Dummy_For_Map for (Owner of XF_Hero[XF_Times]) at XF_Point[8] facing Default building facing degrees
          • Set VariableSet XF_Dummy_Rotator[XF_Times] = (Last created unit)
          • Special Effect - Create a special effect attached to the chest of (Last created unit) using XF_Model_Rotators[0]
          • Set VariableSet XF_Special_ROtator[XF_Times] = (Last created special effect)
          • Custom script: call RemoveLocation(udg_XF_Point[0])
          • Custom script: call RemoveLocation(udg_XF_Point[8])
What I don't understand is... how is this MUI if the index (XF_Times above) is shared?

Wouldn't the following happen?
  1. Unit1 casts spell, trigger starts, index is set to index+1 i.e. 1
  2. Unit2 casts spell just shortly after Unit1 but the trigger for Unit1 is still running, index is set to index+1 again i.e. 2 now
  3. Unit1 trigger now indexes all array variables by index which is now 2 not 1, thus casting incorrectly
Doesn't the fact that the index is shared ruin the whole point of MUI? What am I missing?

Thanks.
 
Level 29
Joined
Sep 26, 2009
Messages
2,594
The index is used to assign unique number to each instance of the spell (or in case of the spell you've posted, a unique number to each chain).
It usually has the following structure:
  • You have an array (or multiple of arrays) to store some data related to the spell in question
  • Unit casts the spell
  • You determine a unique number for that instance of spell (that is done in order to not interfere with data of other active instances). What is often enough is to have an int variable "Index" and just increment it by one
  • All data of the spell instance use same unique number/index across all arrays
  • You usually have a "For each (Integer x) from 1 to Max_Index do" action, which translates to "For each active instance do the following"
  • Once the spell ends, you deindex it... in other words you safely remove data of the instance that ended and decrease the index value by one.

Indexes are not tied to units (unless done so by design). So in your example with unit1 and unit2:
  • unit1 casts spell, index = index+1 = 1. So this spell instance will have index 1
  • unit2 casts spell, index is incremented, this spell instance will have index 2
  • unit1 casts spell again, index is incremented, this spell instance will have index 3

Assuming the spell's cooldown is long enough that the spell ends before unit can cast it again, the situation will look like this:
  • unit1 casts spell, index = index+1 = 1. So this spell instance will have index 1
  • unit2 casts spell, index is incremented, this spell instance will have index 2
  • at time T the first instance (unit1's instance) ends. The trigger will deindex this instance by removing instance 1's data and moving instance 2's data to position (index) 1
  • at this point, unit2's spell instance, which originally had index 2, will now have index 1
  • unit1 casts spell again, index is incremented, this spell instance will have index 2
 
Top