• 🏆 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!

[Trigger] Help me fix my spell indexing

Status
Not open for further replies.
Level 5
Joined
Dec 25, 2014
Messages
111
So, i've been making a spell that to call a group of horsemen to move forward and damaging units. The problem with this is that when i cast another one while the previous is still ongoing, the units i created wont do anything, instead the one i cast before still ongoing and somehow going longer than intended. But if i do it one by one it works. I need help what to fix, thanks.
Here is the triggers

  • To Arms Initialize
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- This trigger is mean to create and initialize any data needed --------
      • Set ToArms_DummyUnit = Knight (Dummy)
      • Set ToArms_DummyAbility = Fuzzy (Dummy)
      • -------- ---- --------
      • Set ToArms_CollisionSize[1] = 150.00
      • Set ToArms_CollisionSize[2] = 150.00
      • Set ToArms_CollisionSize[3] = 150.00
      • Set ToArms_CollisionSize[4] = 150.00
      • -------- ---- --------
      • Set ToArms_Damage[1] = 70.00
      • Set ToArms_Damage[2] = 90.00
      • Set ToArms_Damage[3] = 110.00
      • Set ToArms_Damage[4] = 130.00
      • -------- ---- --------
      • Set ToArms_Distance[1] = 600.00
      • Set ToArms_Distance[2] = 800.00
      • Set ToArms_Distance[3] = 1000.00
      • Set ToArms_Distance[4] = 1200.00
      • -------- ---- --------
      • Set ToArms_Knights[1] = 3
      • Set ToArms_Knights[2] = 4
      • Set ToArms_Knights[3] = 5
      • Set ToArms_Knights[4] = 6
      • -------- ---- --------
      • -------- ---- --------
      • Set ToArms_Offset[1] = 200.00
      • Set ToArms_Offset[2] = 200.00
      • Set ToArms_Offset[3] = 200.00
      • Set ToArms_Offset[4] = 200.00
      • -------- ---- --------
      • Set ToArms_Speed[1] = 325.00
      • Set ToArms_Speed[2] = 325.00
      • Set ToArms_Speed[3] = 325.00
      • Set ToArms_Speed[4] = 325.00
      • -------- ---- --------
      • Set ToArms_AttackType = Chaos
      • Set ToArms_DamageType = Normal
      • -------- ---- --------
      • Set ToArms_SFX = Objects\Spawnmodels\Undead\ImpaleTargetDust\ImpaleTargetDust.mdl
      • -------- ---- --------


  • To Arms Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to To Arms! (Cairne)
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set ToArms_Ability = (Ability being cast)
      • -------- ---- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ToArms_IndexSize Equal to 0
        • Then - Actions
          • Game - Display to (All players) the text: Trigger turned on
          • Trigger - Turn on To Arms Loop <gen>
        • Else - Actions
      • Set ToArms_IndexSize = (ToArms_IndexSize + 1)
      • -------- ---- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ToArms_IndexSize Greater than ToArms_IndexMax
        • Then - Actions
          • Set ToArms_Index[ToArms_IndexSize] = ToArms_IndexSize
          • Set ToArms_IndexMax = ToArms_IndexSize
        • Else - Actions
      • -------- ---- --------
      • Set ToArms_Int = ToArms_Index[ToArms_IndexSize]
      • -------- ---- --------
      • Set ToArms_Unit[ToArms_Int] = (Triggering unit)
      • -------- ---- --------
      • Unit Group - Add ToArms_Unit[ToArms_Int] to ToArms_TempUnitGroup
      • -------- ---- --------
      • Set ToArms_Owner[ToArms_Int] = (Owner of ToArms_Unit[ToArms_Int])
      • -------- ---- --------
      • Set ToArms_AbilityLevel[ToArms_Int] = (Level of ToArms_Ability for ToArms_Unit[ToArms_Int])
      • -------- ---- --------
      • Set ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]] = (ToArms_Distance[ToArms_AbilityLevel[ToArms_Int]] x (Real(ToArms_Knights[ToArms_AbilityLevel[ToArms_Int]])))
      • -------- ---- --------
      • Set ToArms_Angle[ToArms_Int] = (Facing of ToArms_Unit[ToArms_Int])
      • -------- ---- --------
      • Set ToArms_UnitPoint = (Position of ToArms_Unit[ToArms_Int])
      • -------- ---- --------
      • Set ToArms_Point = (ToArms_UnitPoint offset by 0.00 towards ToArms_Angle[ToArms_Int] degrees)
      • -------- ---- --------
      • For each (Integer A) from 1 to ToArms_Knights[ToArms_AbilityLevel[ToArms_Int]], do (Actions)
        • Loop - Actions
          • Set ToArms_Real = (ToArms_Real + (360.00 / (Real(ToArms_Knights[ToArms_AbilityLevel[ToArms_Int]]))))
          • -------- ---- --------
          • Set ToArms_Formation = (ToArms_Point offset by ToArms_Offset[ToArms_AbilityLevel[ToArms_Int]] towards ToArms_Real degrees)
          • -------- ---- --------
          • Unit - Create 1 ToArms_DummyUnit for ToArms_Owner[ToArms_Int] at ToArms_Formation facing ToArms_Angle[ToArms_Int] degrees
          • Unit - Turn collision for (Last created unit) Off
          • Unit Group - Add (Last created unit) to ToArms_TempDummyGroup[ToArms_Int]
          • -------- ---- --------
          • Custom script: call RemoveLocation(udg_ToArms_Formation)
      • -------- ---- --------
      • -------- ---- --------
      • Custom script: call RemoveLocation(udg_ToArms_UnitPoint)
      • Custom script: call RemoveLocation(udg_ToArms_Point)


  • To1 Arms Condtions
    • Events
    • Conditions
      • ((Matching unit) is A structure) Equal to False
      • ((Matching unit) is Ethereal) Equal to False
      • ((Matching unit) is an illusion) Equal to False
      • ((Matching unit) is alive) Equal to True
      • ((Matching unit) is in ToArms_TempTargetGroup[ToArms_DummyIndex]) Equal to False
      • ((Matching unit) belongs to an enemy of ToArms_Owner[ToArms_Int]) Equal to True
    • Actions
      • -------- Configure your conditions above --------


  • To Arms Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer ToArms_Loop) from 1 to ToArms_IndexSize, do (Actions)
        • Loop - Actions
          • -------- ---- --------
          • Set ToArms_Int = ToArms_Index[ToArms_Loop]
          • -------- ---- --------
          • Unit Group - Pick every unit in ToArms_TempUnitGroup and do (Actions)
            • Loop - Actions
              • Set ToArms_TempUnit[ToArms_Int] = (Picked unit)
              • -------- ---- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]] Greater than 0.00
                • Then - Actions
                  • Unit Group - Pick every unit in ToArms_TempDummyGroup[ToArms_Int] and do (Actions)
                    • Loop - Actions
                      • -------- ---- --------
                      • Set ToArms_TempDummy[ToArms_Int] = (Picked unit)
                      • -------- ---- --------
                      • Set ToArms_DummyIndex = (Custom value of ToArms_TempDummy[ToArms_Int])
                      • -------- ---- --------
                      • Set ToArms_DummyLoc[ToArms_Int] = (Position of ToArms_TempDummy[ToArms_Int])
                      • -------- ---- --------
                      • Set ToArms_TargetGroup[ToArms_DummyIndex] = (Units within ToArms_CollisionSize[ToArms_AbilityLevel[ToArms_Int]] of ToArms_DummyLoc[ToArms_Int] matching ((Evaluate To Arms Condtions <gen> conditions) Equal to True))
                      • -------- ---- --------
                      • Unit Group - Pick every unit in ToArms_TargetGroup[ToArms_DummyIndex] and do (Actions)
                        • Loop - Actions
                          • -------- ---- --------
                          • Set ToArms_TempTarget[ToArms_DummyIndex] = (Picked unit)
                          • -------- ---- --------
                          • Unit Group - Add ToArms_TempTarget[ToArms_DummyIndex] to ToArms_TempTargetGroup[ToArms_DummyIndex]
                          • -------- ---- --------
                          • Special Effect - Create a special effect attached to the chest of ToArms_TempTarget[ToArms_DummyIndex] using Abilities\Spells\Other\Stampede\MissileDeath.mdl
                          • Special Effect - Destroy (Last created special effect)
                          • -------- ---- --------
                          • Unit - Create 1 Dummy for ToArms_Owner[ToArms_Int] at ToArms_DummyLoc[ToArms_Int] facing Default building facing degrees
                          • Unit - Add ToArms_DummyAbility to (Last created unit)
                          • Unit - Set level of ToArms_DummyAbility for (Last created unit) to ToArms_AbilityLevel[ToArms_Int]
                          • Unit - Order (Last created unit) to Human Sorceress - Slow ToArms_TempTarget[ToArms_DummyIndex]
                          • Unit - Cause ToArms_TempUnit[ToArms_Int] to damage ToArms_TempTarget[ToArms_DummyIndex], dealing ToArms_Damage[ToArms_AbilityLevel[ToArms_Int]] damage of attack type ToArms_AttackType and damage type ToArms_DamageType
                          • -------- ---- --------
                      • Custom script: call DestroyGroup(udg_ToArms_TargetGroup[udg_ToArms_DummyIndex])
                      • -------- ---- --------
                      • Set ToArms_MovetoLoc[ToArms_Int] = (ToArms_DummyLoc[ToArms_Int] offset by (ToArms_Speed[ToArms_AbilityLevel[ToArms_Int]] / 33.00) towards ToArms_Angle[ToArms_Int] degrees)
                      • -------- ---- --------
                      • Unit - Move ToArms_TempDummy[ToArms_Int] instantly to ToArms_MovetoLoc[ToArms_Int]
                      • -------- ---- --------
                      • Special Effect - Create a special effect at ToArms_MovetoLoc[ToArms_Int] using ToArms_SFX
                      • Special Effect - Set Scale of (Last created special effect) to 0.15
                      • Special Effect - Destroy (Last created special effect)
                      • -------- ---- --------
                      • Custom script: call RemoveLocation(udg_ToArms_MovetoLoc[udg_ToArms_Int])
                      • Custom script: call RemoveLocation(udg_ToArms_DummyLoc[udg_ToArms_Int])
                  • Set ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]] = (ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]] - (ToArms_Speed[ToArms_AbilityLevel[ToArms_Int]] / 33.00))
                • Else - Actions
                  • -------- ---- --------
                  • Unit Group - Pick every unit in ToArms_TempTargetGroup[ToArms_DummyIndex] and do (Actions)
                    • Loop - Actions
                      • -------- ---- --------
                      • Set ToArms_TempTarget[ToArms_DummyIndex] = (Picked unit)
                      • -------- ---- --------
                      • Unit Group - Remove ToArms_TempTarget[ToArms_DummyIndex] from ToArms_TempTargetGroup[ToArms_DummyIndex]
                  • -------- ---- --------
                  • Unit Group - Pick every unit in ToArms_TempDummyGroup[ToArms_Int] and do (Actions)
                    • Loop - Actions
                      • -------- ---- --------
                      • Set ToArms_TempDummy[ToArms_Int] = (Picked unit)
                      • -------- ---- --------
                      • Unit Group - Remove ToArms_TempDummy[ToArms_Int] from ToArms_TempDummyGroup[ToArms_Int]
                      • -------- ---- --------
                      • Unit - Remove ToArms_TempDummy[ToArms_Int] from the game
                  • -------- ---- --------
                  • Set ToArms_Index[ToArms_Loop] = ToArms_Index[ToArms_IndexSize]
                  • Set ToArms_Index[ToArms_IndexSize] = ToArms_Int
                  • Set ToArms_IndexSize = (ToArms_IndexSize - 1)
                  • Set ToArms_Loop = (ToArms_Loop - 1)
                  • -------- ---- --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ToArms_IndexSize Equal to 0
                    • Then - Actions
                      • -------- ---- --------
                      • Unit Group - Remove ToArms_TempUnit[ToArms_Int] from ToArms_TempUnitGroup
                      • -------- ---- --------
                      • Game - Display to (All players) the text: Trigger turned off
                      • Trigger - Turn off (This trigger)
                    • Else - Actions
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,565
Unit Group arrays don't work without being initialized manually:
  • Custom script: set udg_ToArms_TempDummyGroup[X] = CreateGroup()
You need to use Custom script to Create these Groups.

Also, these variables looks entirely unnecessary:
  • ToArms_Index[ToArms_IndexSize]
  • Set ToArms_Int = ToArms_Index[ToArms_Loop]
  • ToArms_IndexMax
ToArms_Loop is already equal to the current cycle in the For Loop so ToArms_Int is unnecessary.

These don't need to be Arrays:
  • Set ToArms_TempDummy[ToArms_Int] = (Picked unit)
  • Set ToArms_TempUnit[ToArms_Int] = (Picked unit)
With that in mind, you can simplify the To Arms Cast trigger to this:
  • To Arms Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to To Arms! (Cairne)
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set ToArms_Ability = (Ability being cast)
      • -------- ---- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ToArms_IndexSize Equal to 0
        • Then - Actions
          • Game - Display to (All players) the text: Trigger turned on
          • Trigger - Turn on To Arms Loop <gen>
        • Else - Actions
      • Set ToArms_IndexSize = (ToArms_IndexSize + 1)
      • -------- ---- --------
      • Set ToArms_Unit[ToArms_IndexSize] = (Triggering unit)
      • -------- ---- --------
      • Unit Group - Add ToArms_Unit[ToArms_IndexSize] to ToArms_TempUnitGroup
      • -------- ---- --------
      • Set ToArms_Owner[ToArms_IndexSize] = (Owner of ToArms_Unit[ToArms_IndexSize])
      • -------- ---- --------
      • Set ToArms_AbilityLevel[ToArms_IndexSize] = (Level of ToArms_Ability for ToArms_Unit[ToArms_IndexSize])
      • -------- ---- --------
      • Set ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_IndexSize]] = (ToArms_Distance[ToArms_AbilityLevel[ToArms_IndexSize]] x (Real(ToArms_Knights[ToArms_AbilityLevel[ToArms_IndexSize]])))
      • -------- ---- --------
      • Set ToArms_Angle[ToArms_IndexSize] = (Facing of ToArms_Unit[ToArms_IndexSize])
      • -------- ---- --------
      • Set ToArms_UnitPoint = (Position of ToArms_Unit[ToArms_IndexSize])
      • -------- ---- --------
      • Set ToArms_Point = (ToArms_UnitPoint offset by 0.00 towards ToArms_Angle[ToArms_IndexSize] degrees)
      • -------- ---- --------
      • -------- CREATE THE UNIT GROUP THAT CONTAINS THE CASTER'S DUMMY UNITS --------
      • Custom script: set udg_ToArms_TempDummyGroup[udg_ToArms_IndexSize] = CreateGroup()
      • -------- ---- --------
      • For each (Integer A) from 1 to ToArms_Knights[ToArms_AbilityLevel[ToArms_IndexSize]], do (Actions)
        • Loop - Actions
          • Set ToArms_Real = (ToArms_Real + (360.00 / (Real(ToArms_Knights[ToArms_AbilityLevel[ToArms_IndexSize]]))))
          • -------- ---- --------
          • Set ToArms_Formation = (ToArms_Point offset by ToArms_Offset[ToArms_AbilityLevel[ToArms_IndexSize]] towards ToArms_Real degrees)
          • -------- ---- --------
          • Unit - Create 1 ToArms_DummyUnit for ToArms_Owner[ToArms_IndexSize] at ToArms_Formation facing ToArms_Angle[ToArms_IndexSize] degrees
          • Set ToArms_TempDummy = (Last created unit)
          • Unit - Turn collision for ToArms_TempDummy Off
          • Unit Group - Add ToArms_TempDummy to ToArms_TempDummyGroup[ToArms_IndexSize]
          • -------- ---- --------
          • -------- CREATE A UNIT GROUP FOR THIS DUMMY SO IT WON'T HIT THE SAME TARGET MULTIPLE TIMES --------
          • Custom script: set udg_ToArms_TargetGroup[GetUnitUserData(udg_ToArms_TempDummy)] = CreateGroup()
          • -------- ---- --------
          • Custom script: call RemoveLocation(udg_ToArms_Formation)
      • -------- ---- --------
      • Custom script: call RemoveLocation(udg_ToArms_UnitPoint)
      • Custom script: call RemoveLocation(udg_ToArms_Point)
Note the creation of the Unit Groups, I create one that contains all of the Dummys that are linked to the index of the spell. Then I create a new Unit Group for each Dummy unit which is used to track their targets to prevent multiple hits on the same target. I saw you were using a Unit Indexer so I used the Dummy's custom value as the [index] of the Unit Group.

With these changes in mind the Loop trigger will need to be adjusted as well:

1) You shouldn't be destroying udg_ToArms_TargetGroup until the very end of the spell. This Unit Group needs to remain active throughout the spell in order to prevent units from being hit multiple times by the same Dummy. With this in mind, you should be Adding targets that get hit by the Dummys to this Unit Group if they aren't already in it of course.
  • Set TempUG = Units within range of Dummy matching (Matching unit is in ToArms_TargetGroup[custom value of Dummy] Equal false...
  • Unit Group - Pick every unit in TempUnitGroup and do Add (Picked unit) to ToArms_TargetGroup[custom value of Dummy]
  • Custom script: call DestroyGroup(udg_TempUG)
2) You have a lot of unnecessary variables / arrays in here as well. ToArms_Loop should be referenced when trying to get information about the current Loop cycle. For example:
  • Unit Group - Pick every unit in ToArms_TempDummyGroup[ToArms_Loop] and do (Actions)
3) At the end of the Loop trigger in the Else - Actions section you're making a few mistakes. You should be Destroying the TempDummyGroup after clearing each Dummy's Unit Group and Removing them from the game. Then you need to Set ToArms_FinalDistance[Loop] to be equal to ToArms_FinalDistance[Index] and do the same for every other To_Arms variable associated with the Loop. You should also Remove the Caster (ToArms_Unit) from TempUnitGroup since it's finished casting the spell:
  • Else - Actions
    • Unit Group - Remove ToArms_Unit[ToArms_Loop] from ToArms_TempUnitGroup
    • Unit Group - Pick every unit in ToArms_TempDummyGroup[ToArms_Loop] and do (Actions)
      • Loop - Actions
        • Set udg_ToArms_TempDummy = (Picked unit)
        • Custom script: call DestroyGroup(udg_ToArms_TargetGroup[GetUnitUserData(udg_ToArms_TempDummy)])
        • Unit - Remove ToArms_TempDummy from the game
    • Custom script: call DestroyGroup(udg_ToArms_TempDummyGroup[ToArms_Loop])
    • -------- ---- --------
    • Set ToArms_TempDummyGroup[ToArms_Loop] = ToArms_TempDummyGroup[ToArms_IndexSize]
    • Set ToArms_FinalDistance[ToArms_Loop] = ToArms_FinalDistance[ToArms_IndexSize]
    • Set ToArms_Unit[ToArms_Loop] = ToArms_Unit[ToArms_IndexSize]
    • Set ToArms_Owner[ToArms_Loop] = ToArms_Owner[ToArms_IndexSize]
    • Set ToArms_Ability[ToArms_Loop] = ToArms_Ability[ToArms_IndexSize]
    • Set ToArms_Angle[ToArms_Loop] = ToArms_Angle[ToArms_IndexSize]
    • -------- ---- --------
    • Set ToArms_Loop = (ToArms_Loop - 1)
    • Set ToArms_IndexSize = (ToArms_IndexSize - 1)
    • -------- ---- --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ToArms_IndexSize Equal to 0
    • Then - Actions
      • Game - Display to (All players) the text: Trigger turned off
      • Trigger - Turn off (This trigger)
    • Else - Actions
 
Last edited:
Level 25
Joined
Sep 26, 2009
Messages
2,381
well, I took a look at your triggers and the general issue is your overengineering of the code and possibly lack of understanding how triggers and loops work.

As I understand it, you want a spell where the caster summons a bunch of knights that charge in some direction and if they collide with some enemy unit, they deal damage to the unit and slow them.
But the way you made a rather simple MUI spell overly complicated with lots of unneeded arrays and actions and strange indices, coupled with strange and undescriptive variable names is I think the reason why you cannot make it work and are lost in it yourself :D

There is no reason to use arrays for everything because it is supposed to be MUI.
Just in the 'Initialize' trigger, I can see that collision size, speed and offset use same numbers for all levels... so why even use arrays for these? Granted, you may decide in the future that these values should be also different per level, but you should start your triggers simple and build up the complexity once you know it works.
I wrote that you possibly lack the understanding of how triggers and loops work based on the overuse of arrays, so just to clear things up:
  • one and only one trigger is ever executed at a time. If multiple triggers should be executed at same time, they are instead internally put in a queue an executed one by one (literally a trigger is executed - all its actions are executed and once that is done, another trigger from the queue is picked up and executed). This is very fast so to us humans it may seem like it executes at once in parallel
    • the exception to this rule is basically when your trigger has an action for executing another trigger - like your "(Evaluate To Arms Condtions <gen> conditions)" when setting the ToArms_TargetGroup[ToArms_DummyIndex] variable
  • loops are executed sequentially. Meaning if you have a loop "Unit Group - Pick every unit in ToArms_TempUnitGroup and do (Actions)" then the trigger picks first unit from the unit group, then for this unit it executes all actions placed in the "Loop - Actions" block and after that it picks the second unit and executes all actions in the "Loop - Actions" block and so on until it iterates over each unit
    • that means things like "Set ToArms_TempUnit[ToArms_Int] = (Picked unit)" can instead be "Set ToArms_TempUnit = (Picked unit)" - no array, just a single-value variable
Perhaps another thing that you should choose better is variable names and also name a variable as "Temp" when the variable is truly temporal. I can see many places in your triggers that you use variables like ToArms_TempUnitGroup which actually is not a temp variable, since it is a group for keeping track of all your casters over the duration of a spell.
A better/more descriptive name for that group would be ToArms_Casters.
Another example is this: ToArms_FinalDistance - why is it called FinalDistance, if you subtract the range from it? A more descriptive name would be RemaniningDistance and then you evaluate if "RemainingDistance is <= 0.0" which makes more sense.
Of course, strange variable names are not the reason it is not working, it just makes it harder to understand.

One of the issues for your trigger not working is the loop trigger:
  • For each (Integer ToArms_Loop) from 1 to ToArms_IndexSize, do (Actions)
    • Loop - Actions
      • -------- ---- --------
      • Set ToArms_Int = ToArms_Index[ToArms_Loop]
      • -------- ---- --------
      • Unit Group - Pick every unit in ToArms_TempUnitGroup and do (Actions)
        • Loop - Actions
          • Set ToArms_TempUnit[ToArms_Int] = (Picked unit)
          • -------- ---- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]] Greater than 0.00
            • Then - Actions
              • Unit Group - Pick every unit in ToArms_TempDummyGroup[ToArms_Int] and do (Actions)
                • //some stuff here
              • Set ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]] = (ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]] - (ToArms_Speed[ToArms_AbilityLevel[ToArms_Int]] / 33.00))
            • //trigger continues on
If you cast the spell two times at the same time, then ToArms_IndexSize will be 2.
So the "For each..." loop executes two times.
You also have two casters in the ToArms_TempUnitGroup, so the "Unit Group - Pick every..." also executes two times.
That means for each active instance you update "Set ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]]" two times and you move your knights two times.

Finally, the FinalDistance's index is completely bad.
In your "Cast" trigger you set the final distance as
  • Set ToArms_AbilityLevel[ToArms_Int] = (Level of ToArms_Ability for ToArms_Unit[ToArms_Int])
  • -------- ---- --------
  • Set ToArms_FinalDistance[ToArms_AbilityLevel[ToArms_Int]] = (ToArms_Distance[ToArms_AbilityLevel[ToArms_Int]] x (Real(ToArms_Knights[ToArms_AbilityLevel[ToArms_Int]])))
And in similar fashion you also handle it in loop trigger( as shown in the loop trigger part I posted earlier).
So how does this work in practice?
  1. First unit casts the spell -> ToArms_Int will be 1
  2. ToArms_AbilityLevel[ToArms_Int] => ToArms_AbilityLevel[1] = (Level of abiltiy for that unit) => which for this sake will be level 1
  3. ToArms_FinalDistance[ToArms_AbilityLevel[1]] => ToArms_AbilityLevel[1] contains level of ability which is 1 => ToArms_FinalDistance[1] = some distance
  4. Now another unit casts spell -> ToArms_Int will be 2
  5. ToArms_AbilityLevel[2] = level of ability for that unit which will again be level 1
  6. ToArms_FinalDistance[ToArms_AbilityLevel[2]] => ToArms_AbilityLevel[2] contains level of ability which for this unit is also 1 => ToArms_FinalDistance[1] = some new distance
And that is why your spell is not working - the second instance overwrites first instance's finalDistance instead of setting its own FinalDistance.
That is the reason why the first cast's knights are running way longer while second cast's knights stand in place - because second cast's finalDistance starts at 0.0 while the first cast's FinalDistance is reset to initial value
 
Level 39
Joined
Feb 27, 2007
Messages
5,023
You need to use Custom script to Create these Groups.
You can do it in GUI with either of these:
  • Set GroupVariable[whatever] = (Units in No region)
  • Set GroupVariable[whatever] = (Units of type No unit-type)
There is no reason to use arrays for everything because it is supposed to be MUI.
Parallel arrays are a perfectly valid way to instance separate casts. After all, that's just what vJASS structs are under the hood.
 
Status
Not open for further replies.
Top