• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Unsure about trigger

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
I've started making some spells of my own. This one is for my pokemon map. The problem is if the spell is cast by multiple units at the same time... Will the variables still work?
  • Nightshade
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Nightshade (Level 4)
    • Actions
      • Set Nightshade_Caster = (Casting unit)
      • Set Nightshade_Target = (Target unit of ability being cast)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Nightshade (Level 4) for Nightshade_Caster) Equal to 1
        • Then - Actions
          • Unit - Cause Nightshade_Caster to damage Nightshade_Target, dealing ((Real((Hero level of Nightshade_Caster))) x 4.00) damage of attack type Spells and damage type Normal
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Nightshade (Level 4) for Nightshade_Caster) Equal to 2
            • Then - Actions
              • Unit - Cause Nightshade_Caster to damage Nightshade_Target, dealing ((Real((Hero level of Nightshade_Caster))) x 8.00) damage of attack type Spells and damage type Normal
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Nightshade (Level 4) for Nightshade_Caster) Equal to 3
                • Then - Actions
                  • Unit - Cause Nightshade_Caster to damage Nightshade_Target, dealing ((Real((Hero level of Nightshade_Caster))) x 12.00) damage of attack type Spells and damage type Normal
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Nightshade (Level 4) for Nightshade_Caster) Equal to 4
                    • Then - Actions
                      • Unit - Cause Nightshade_Caster to damage Nightshade_Target, dealing ((Real((Hero level of Nightshade_Caster))) x 16.00) damage of attack type Spells and damage type Normal
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Level of Nightshade (Level 4) for Nightshade_Caster) Equal to 5
                        • Then - Actions
                          • Unit - Cause Nightshade_Caster to damage Nightshade_Target, dealing ((Real((Hero level of Nightshade_Caster))) x 20.00) damage of attack type Spells and damage type Normal
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Nightshade (Level 4) for Nightshade_Caster) Equal to 6
                            • Then - Actions
                              • Unit - Cause Nightshade_Caster to damage Nightshade_Target, dealing ((Real((Hero level of Nightshade_Caster))) x 25.00) damage of attack type Spells and damage type Normal
                            • Else - Actions
 
Level 3
Joined
Nov 10, 2011
Messages
51
i think when more than a unit use that ability, the last unit used the ability will be the NightShade_Caster variable, other way it will leaks. you can avoid that by doing the following steps:

1- make the variable array and set the size to 1.
2-use that trigger instead you are using.

  • NightShade
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to NightShade (Level 4)
    • Actions
      • Set NightShade_Caster[(Player number of (Owner of (Casting unit)))] = (Casting unit)
      • Set NightShade_Target[(Player number of (Owner of (Casting unit)))] = (Target unit of ability being cast)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
i think when more than a unit use that ability, the last unit used the ability will be the NightShade_Caster variable, other way it will leaks. you can avoid that by doing the following steps

It can only cause one leak per game per a global variable used. And that is insignificant. The memory leak is so small it is difficult to even measure it.

No arrays should be used in this trigger :)
 
Level 3
Joined
Nov 10, 2011
Messages
51
Maker said:
It can only cause one leak per game per a global variable used. And that is insignificant. The memory leak is so small it is difficult to even measure it.

No arrays should be used in this trigger :)

you the best maker
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Instead of using the variable "NightShade_Caster", why dont you just use "Event Response - Casting Unit"? It will save you the space that the variable would take up

By using native function, without saving it to a variable and if you use that function more than one time, you should use variable, why ?

Because, once you set the native function to a variable, it will not generate new set of function everytime you repeat the same usage process in a single trigger, therefore it's less efficient if you keep calling the same function, when you can actually save it first, and call it whenever necessary (in a single trigger)

But if you use it only once per single trigger, then it's okay to call it by its native function (doesn't need to save it to variable)

This is all matter of efficiency.
 
Status
Not open for further replies.
Top