• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] How to set different variable for each trigger execution

Status
Not open for further replies.
Level 13
Joined
Mar 24, 2013
Messages
1,105
Visualize: Dynamic Indexing

Basically every time you fire the trigger you increment a counter and use variables that are arrays.

Trigger Fires

count = count + 1
unit[count] = myunit

Trigger fires again
count = count + 1
unit[count] = myotherunit

Now you have unit[1] = myunit and unit[2] = myotherunit

Keep in mind arrays only work up 8192.

If you elaborate on what you wish to accomplish people can better guide on how to create whatever you need.
 
Last edited:
Level 15
Joined
Sep 6, 2015
Messages
576
Checked both, they work at start, but then both have the same problem after with my trigger. Here is the exact trigger:

  • Untitled Trigger 007
    • Events
      • Unit - Dreadlord 0175 <gen> Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Sleep
    • Actions
      • Set temp_integer = (Execution count of (This trigger))
      • Set counter = (counter + 1)
      • Set unit1[temp_integer] = (Target unit of ability being cast)
      • Unit - Make unit1[temp_integer] Invulnerable
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Sleep for (Casting unit)) Equal to 1
        • Then - Actions
          • Wait 20.00 seconds
          • Unit - Make unit1[temp_integer] Vulnerable
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Sleep for (Casting unit)) Equal to 2
            • Then - Actions
              • Wait 40.00 seconds
              • Unit - Make unit1[temp_integer] Vulnerable
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Sleep for (Casting unit)) Equal to 3
                • Then - Actions
                  • Wait 60.00 seconds
                  • Unit - Make unit1[temp_integer] Vulnerable
                • Else - Actions
(The Set counter = (counter + 1) action is disabled here, but it doesn't show when I copy it to the site.)
When I use both solutions they work when I cast sleep on two units and make the right units invulnerable, however after the wait time is over only the second unit becomes vulnerable again at the time the first one should, and the first unit stays invulnerable forever.
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
Ah, well yes using Waits will result in it not working.
If you read the tutorial I linked it goes way in depth and helps you understand what I'm about to say.

So what you need to do is this:

Generic Unit Event Starts the effect of an ability (This way you can have multiple dreadlords casting or multiple units asleep at the same time.)
Condition - your ability
actions

Counter = Counter + 1
Set SleepUnit[Counter] = Target Unit (Unit Variable)
Set SleepDuration[Counter] = 20. * Level of Sleep for Triggering Unit (Real Variable)
Make SleepUnit[Counter] Invulnerable
(Currently this just makes the unit unable to be attacked or cast spells on, not really asleep. You should probably stun then for the duration and make then invul)

If Counter = 1 Then Turn on Sleep Loop
Else leave blank




New Trigger Sleep Loop
Periodic Event
Every .04 seconds of game time

For Each TempInteger from 1 to Counter (TempInteger is an Integer Var)
Set SleepDuration[TempInteger] = SleepDuration[TempInteger] - .04

If SleepDuration[TempInteger] <= 0 then (We know the sleep is over, lets wake them up)
Make SleepUnit[TempInteger] Vulnerable
Set SleepUnit[TempInteger] = SleepUnit[Counter]
Set SleepDuration[TempInteger] = SleepDuration[Counter]
Set TempInteger = TempInteger - 1
Set Counter = Counter - 1
If Counter = 0 then
Turn off This trigger
Else
Leave blank as when its asleep we don't need to do anything.
 
Level 15
Joined
Sep 6, 2015
Messages
576
I did everything as you said, except:
Set SleepDuration[TempInteger] = SleepDuration[TempInteger] - .04
Because the integer value cannot have partial numbers, only whole, so I left out that "-.04".
And it doesn't work, or I messed something up. It makes the unit invulnerable, but it doesn't make it vulnerable after. Here are the triggers:

  • Untitled Trigger 008
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Sleep
    • Actions
      • Set counter = (counter + 1)
      • Set SleepUnit[counter] = (Target unit of ability being cast)
      • Set SleepDuration[counter] = (20 x (Level of Sleep for (Triggering unit)))
      • Unit - Make SleepUnit[counter] Invulnerable
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • counter Equal to 1
        • Then - Actions
          • Trigger - Turn on Untitled Trigger 009 <gen>
        • Else - Actions
  • Untitled Trigger 009
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • For each (Integer TempInteger) from 1 to counter, do (Actions)
        • Loop - Actions
          • Set SleepDuration[TempInteger] = SleepDuration[TempInteger]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SleepDuration[TempInteger] Less than or equal to 0
            • Then - Actions
              • Unit - Make SleepUnit[TempInteger] Vulnerable
              • Set SleepUnit[TempInteger] = SleepUnit[counter]
              • Set SleepDuration[TempInteger] = SleepDuration[counter]
              • Set TempInteger = (TempInteger - 1)
              • Set counter = (counter - 1)
              • If (counter Equal to 0) then do (Trigger - Turn off (This trigger)) else do (Do nothing)
            • Else - Actions
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
It will not work because the SleepDuration will never get to the 0 value. You may need to change that integer variable to a real variable so you can decrease it based on an interval of .04.
You also need to make the condition 'OR' statement together with the duration and if the target dies.

Anyway, waits can be easily use in this type of spell if your familliar in variable shadowing.

Edit: use 1 second interval for that periodic timer since the duration is appropriate, so it will just iterate one at a second.
 
Last edited:
Level 15
Joined
Sep 6, 2015
Messages
576
It works now finally.
It will not work because the SleepDuration will never get to 0 value. You may need to change that integer variable to a real variable so you can decrease it based on an interval.
Set SleepDuration[Counter] = 20. * Level of Sleep for Triggering Unit (Real Variable)
I had changed that real variable to integer because "Level of Sleep for Triggering Unit" couldn't be used with a real variable. Now I added the ability level condition in front of everything and changed it to real and it works fine. Here are the complete triggers:

  • Trigger 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Sleep
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Sleep for (Triggering unit)) Equal to 1
        • Then - Actions
          • Set counter = (counter + 1)
          • Set SleepUnit[counter] = (Target unit of ability being cast)
          • Set SleepDuration[counter] = (20.00 x 1.00)
          • Unit - Make SleepUnit[counter] Invulnerable
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • counter Equal to 1
            • Then - Actions
              • Trigger - Turn on Untitled Trigger 009 <gen>
            • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Sleep for (Triggering unit)) Equal to 2
            • Then - Actions
              • Set counter = (counter + 1)
              • Set SleepUnit[counter] = (Target unit of ability being cast)
              • Set SleepDuration[counter] = (20.00 x 2.00)
              • Unit - Make SleepUnit[counter] Invulnerable
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • counter Equal to 1
                • Then - Actions
                  • Trigger - Turn on Untitled Trigger 009 <gen>
                • Else - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Sleep for (Triggering unit)) Equal to 3
                • Then - Actions
                  • Set counter = (counter + 1)
                  • Set SleepUnit[counter] = (Target unit of ability being cast)
                  • Set SleepDuration[counter] = (20.00 x 3.00)
                  • Unit - Make SleepUnit[counter] Invulnerable
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • counter Equal to 1
                    • Then - Actions
                      • Trigger - Turn on Untitled Trigger 009 <gen>
                    • Else - Actions
                • Else - Actions
  • Trigger 2
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • For each (Integer TempInteger) from 1 to counter, do (Actions)
        • Loop - Actions
          • Set SleepDuration[TempInteger] = (SleepDuration[TempInteger] - 0.04)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SleepDuration[TempInteger] Less than or equal to 0.00
            • Then - Actions
              • Unit - Make SleepUnit[TempInteger] Vulnerable
              • Set SleepUnit[TempInteger] = SleepUnit[counter]
              • Set SleepDuration[TempInteger] = SleepDuration[counter]
              • Set TempInteger = (TempInteger - 1)
              • Set counter = (counter - 1)
              • If (counter Equal to 0) then do (Trigger - Turn off (This trigger)) else do (Do nothing)
            • Else - Actions
Solved! +Rep to all. (Edit: Can't give rep to jakeZinc because I have to rep 5 other users before repping him again.)

Edit 2:
You also need to make the condition 'OR' statement together with the duration and if the target dies.
What do you mean with that OR condition? Where to add it and what exactly to add?
 
Last edited:
Level 20
Joined
Aug 13, 2013
Messages
1,696
No, nesting the condition for the level is not the solution so remove that if's statements in the trigger 1.

All you have to do is to find the GUI function inside the parameter of that real variable;
( Conversion - Integer to Real ) or known as I2R.
( It seems pOke forgot to include that conversion )
then you can now freely put an integer value
( level ) into that real variable.
So it should look like:
  • Set SleepDuration[counter] = ( 20 x (Real(Level of Ability from triggering unit)))

Put the 'Or' statement here together with the checking if sleep unit is dead.
  • Or - ( Multiple Conditions )
  • SleepDuration[TempInteger] Less than or equal to 0.00
  • ( SleepUnit[TempInteger] is dead ) Equal to true
^ Unit is dead can be found on a boolean condition.
Remember to put them inside the 'Or' statement or else it will considered the statement as 'And' thus returning the statement to false if both statement don't agree from each other.

If you're interested in further;
http://www.hiveworkshop.com/pastebin/bb36a403d199a9674f100c0b7bf81eff7063/
 
Last edited:
Level 15
Joined
Sep 6, 2015
Messages
576
No, nesting the condition for the level is not the solution so remove that if's statements in the trigger 1.

All you have to do is to find the GUI function inside the parameter of that real variable;
( Conversion - Integer to Real ) or known as I2R.
( It seems pOke forgot to include that conversion )
then you can now freely put an integer value
( level ) into that real variable.
So it should look like:
  • set.gif
    Set SleepDuration[counter] = ( 20 x (Integer(Level of Ability from triggering unit)))



Put the 'Or' statement here together with the checking if sleep unit is dead.
  • if.gif
    Or - ( Multiple Conditions )
  • if.gif
    SleepDuration[TempInteger] Less than or equal to 0.00
  • if.gif
    ( SleepUnit[TempInteger] is dead ) Equal to true

^ Unit is dead can be found on a boolean condition.
Remember to put them inside the 'Or' statement or else it will considered the statement as 'And' thus returning the statement to false if both statement don't agree from each other.
Ok, thanks. Here are the final triggers:

  • Trigger 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Sleep
    • Actions
      • Set counter = (counter + 1)
      • Set SleepUnit[counter] = (Target unit of ability being cast)
      • Set SleepDuration[counter] = (20.00 x (Real((Level of Sleep for (Triggering unit)))))
      • Unit - Make SleepUnit[counter] Invulnerable
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • counter Equal to 1
        • Then - Actions
          • Trigger - Turn on Trigger 2 <gen>
        • Else - Actions
  • Trigger 2
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • For each (Integer TempInteger) from 1 to counter, do (Actions)
        • Loop - Actions
          • Set SleepDuration[TempInteger] = (SleepDuration[TempInteger] - 0.04)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • SleepDuration[TempInteger] Less than or equal to 0.00
                  • (SleepUnit[TempInteger] is dead) Equal to True
            • Then - Actions
              • Unit - Make SleepUnit[TempInteger] Vulnerable
              • Set SleepUnit[TempInteger] = SleepUnit[counter]
              • Set SleepDuration[TempInteger] = SleepDuration[counter]
              • Set TempInteger = (TempInteger - 1)
              • Set counter = (counter - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • counter Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
I checked that already, I will try it if I will be making any such spells.
You could try using local variables. They are unique for each function call but stop existing on function return.
I don't know anything about them. How to use them, how do they function and how would they fit these triggers?
 
Last edited:
Level 20
Joined
Aug 13, 2013
Messages
1,696
They are JASS, yes you can also use locals to shadow a global variable and using waits but I think it's better what you've already done on here.

Also a suggestion; the one line if conditon is not recommended and it is just doing the same as the normal if block so in this way there's no need to put that DoNothing() func.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I don't know anything about them. How to use them, how do they function and how would they fit these triggers?
They are only available with JASS. They function like local variables in other programming languages. The only major difference is that local declared local handle variables need to be nulled before function return due to a bug resulting in a reference counter reference leak.

I am unsure if they are useful with your current trigger, but they did seem to match the description of what you were after at first.
 
Status
Not open for further replies.
Top