• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Shared Variables across Abilities

Status
Not open for further replies.
Level 5
Joined
May 13, 2012
Messages
68
Okay. I've been copying various GUI triggers from spells of those from Hive. Unfortunately, I'm worried abilities cannot be used at same time if both reference to same variable e.g. TempGroup, TempUnit, etc. How do I fix this? I'm currently copying variables so that they are unique to ability but this is going to take AGES and I've got like 20+ abilities that are affected.
:goblin_jawdrop:

I've uploaded my map if you want to check.
 

Attachments

  • MHW 2.w3x
    8 MB · Views: 57
Last edited:
Level 28
Joined
Sep 26, 2009
Messages
2,520
If the ability is coded correctly, then TempGroup (or anything with Temp/Temporal, etc.) means that it is used only when the triggers run, once the trigger finishes all actions, that variable will no longer hold any meaningful data that you don't want to lose.

The game doesn't run more than 1 trigger at a time, however we do not notice it because it runs the trigger so fast (unless some specific actions are used, but that's something else).

Example of using Temporal Variables:
  • Melee Initialization
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to *some ability*
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Set TempGroup = (Units within 500.00 of TempPoint matching (*some conditions*)
      • Set TempInt = (Number of units in TempGroup)
      • Unit - Cause (Triggering unit) to damage (Triggering unit), dealing (20.00 x (Real(TempInt))) damage of attack type Spells and damage type Normal
  • ... removing leaks here...
As you can see here, TempPoint, TempGroup and TempInt variables are used only in this trigger run. Once the trigger finishes all actions, these variables lose their purpose, so we don't worry about them being overwritten.


This is incorrectly set up temporal variables:
  • Melee Initialization
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to *some ability*
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Set TempGroup = (Units within 500.00 of TempPoint matching (*some conditions*)
      • Set TempInt = (Number of units in TempGroup)
      • Wait 2.00 seconds
      • Unit - Cause (Triggering unit) to damage (Triggering unit), dealing (20.00 x (Real(TempInt))) damage of attack type Spells and damage type Normal
  • ... clear leaks...
As you can see here, the variables here are no longer Temporal or Temp... even if they contain Temp in their name, they are used to store data for some time.
During the 2 second wait other triggers will run, which may overwrite data saved by this trigger.
In this case, the trigger should have its own unique variables

  • Trigger 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to *some ability*
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • Set TempGroup = (Units within 500.00 of TempPoint matching (*some conditions*)
      • Set TempInt = (Number of units in TempGroup)
      • Unit - Cause (Triggering unit) to damage UNIT_A, dealing (20.00 x (Real(TempInt))) damage of attack type Spells and damage type Normal
  • ... clear leaks...
  • Trigger 2
    • Events
      • Unit - UNIT_A Takes damage
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInt Greater than 0
        • Then - Actions
          • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + (20.00 x (Real(TempInt))))
        • Else - Actions
This is also incorrect use. In this case, what I expect is that the unit UNIT_A will take 20*(number of nearby units) damage and that same UNIT_A should in other trigger gain 20*(number of nearby units) mana when it takes damage.

The amount of nearby units is referenced here as TempInt. Now in this trigger I may expect that the value TempInt will be the same (that it will still contain the value store in trigger 1), but it may not be the case. It may get overwritten by that time.
 
Level 18
Joined
May 11, 2012
Messages
2,103
If they reference to variables named "TempUnit", "TempUnitGroup", "TempPoint" etc...
then thoser spells will never be used at the same time because spells using those variables are probably instant.
SO I guess you're safe.
Don't create new variables for instant actions because they are unnecessary (I made huge mistake by doing this, and ended up with shit ton of variables).

Nichilus beat me to the post.
 
Status
Not open for further replies.
Top