New to local variables, need help with points in MUI loop

Level 9
Joined
Mar 17, 2016
Messages
133
Hi, I'm really struggling with this. I've tried quite a few ways of doing it and I'm sure that this is one of the best ways that I can accomplish (I don't know jass) but I can't for the life of me understand what is going wrong. Here is the trigger:

  • FrozenMaw Copy
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Frozen Maw (Guardian)
    • Actions
      • Custom script: local integer i
      • Custom script: local location l = GetSpellTargetLoc()
      • -------- ------- --------
      • -------- Loop number under 8192 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • GuardIntA Equal to 8192
        • Then - Actions
          • Set VariableSet GuardIntA = 0
        • Else - Actions
          • Set VariableSet GuardIntA = (GuardIntA + 1)
      • -------- ------- --------
      • -------- Set local variable to match number loop below 8192 --------
      • -------- Set second integer to be said number --------
      • Custom script: set i = udg_GuardIntA
      • Custom script: set udg_GuardIntB = i
      • -------- ------- --------
      • For each (Integer GuardIntCArray[GuardIntB]) from 1 to 4, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String(GuardIntCArray[GuardIntB]))
          • Wait 0.14 seconds
          • Custom script: set udg_GuardTempPoint = l
          • Custom script: set l = null
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 225.00 of GuardTempPoint.) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A structure) Equal to False
                  • ((Picked unit) is Magic Immune) Equal to False
                • Then - Actions
                  • Unit - Cause (Triggering unit) to damage (Picked unit), dealing (15.00 + (7.50 x (Real((Level of Frozen Maw (Guardian) for (Triggering unit)))))) damage of attack type Spells and damage type Normal
                • Else - Actions
          • Custom script: set udg_GuardIntB = i
          • Special Effect - Create a special effect at GuardTempPoint using war3mapImported\Ephemeral Slash Midnight.mdx
          • Set VariableSet GuardTempSE = (Last created special effect)
          • Special Effect - Destroy GuardTempSE
          • Custom script: set l = udg_GuardTempPoint
          • Custom script: call RemoveLocation(udg_GuardTempPoint)
      • -------- ------- --------
      • Custom script: set l = null
      • -------- ------- --------

From what I understand the trigger works, but the issue has to do with the point "GuardTempPoint" as when I print the numbers it goes 1,2,3,4 as intended but only the first special effect and damage instances appear.

Anyone know the issue?
 

Uncle

Warcraft Moderator
Level 48
Joined
Aug 10, 2018
Messages
4,691
The issue is that you're removing GuardTempPoint, which is a pointer to "l", so you're really removing l.

So you want to replace:
  • Custom script: set udg_GuardTempPoint = l
with:
  • Custom script: set udg_GuardTempPoint = OffsetLocation(l, 0, 0)
This creates a new Point so l and GuardTempPoint are no longer the same thing.

This means that you want to get rid of some other lines like from the For Loop:
  • Custom script: set l = udg_GuardTempPoint
  • Custom script: set l = null
You only need to null l at the very end after the For Loop (when you're done using it). You shouldn't touch it at all throughout the trigger until the very end.

And don't forget to remove l before you null it since it's a Point and can leak.
  • Custom script: call RemoveLocation(l)
  • Custom script: set l = null
Some other minor things. This seems useless:
  • Set VariableSet GuardTempSE = (Last created special effect)
You set GuardTempSE then immediately destroy it, which means that the variable served no purpose. Just forget the variable and go right to destroying the last created special effect.

Also, 8192 is not the Array Size limit in the later versions, it's 32768.


Edit:
And that For Loop seems like an ugly solution. Scrap all of that and do this kind of Loop instead:
  • Actions
    • Custom script: local integer i = 0
    • Custom script: loop
    • Custom script: exitwhen i == 4
    • -------- do stuff: --------
    • Custom script: set i = i + 1
    • Game - Display to (All players) the text: it works
    • Wait 0.14 seconds
    • -------- //stop// --------
    • Custom script: endloop
This will loop the actions 4 times without the need for all of those integer variables and ugly GUI workarounds.

Here's what the full trigger would look like:
  • Ability Fix
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to YourAbility
    • Actions
      • Custom script: local integer i = 0
      • Custom script: local location l = GetSpellTargetLoc()
      • -------- --------
      • Custom script: loop
      • Custom script: exitwhen i == 4
      • -------- --------
      • Custom script: set i = i + 1
      • Wait 0.14 seconds
      • Custom script: set udg_GuardTempPoint = OffsetLocation(l, 0, 0)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 225.00 of GuardTempPoint.) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
              • ((Picked unit) is A structure) Equal to False
              • ((Picked unit) is Magic Immune) Equal to False
            • Then - Actions
              • Unit - Cause (Triggering unit) to damage (Picked unit), dealing SomeValue damage of attack type Spells and damage type Normal
            • Else - Actions
      • Special Effect - Create a special effect at GuardTempPoint using SomeArt
      • Special Effect - Destroy (Last created special effect)
      • Custom script: call RemoveLocation(udg_GuardTempPoint)
      • -------- --------
      • Custom script: endloop
      • -------- --------
      • Custom script: call RemoveLocation(l)
      • Custom script: set l = null
At this point you might as well learn Jass since you're using so much Custom Script anyway (or better, Lua) :p
 

Attachments

  • Example Loop DoT.w3m
    18 KB · Views: 19
Last edited:
Level 9
Joined
Mar 17, 2016
Messages
133
Dang, you're literally a legend when it comes to this stuff. I shouldve known there was a better way, but I am very new to all this custom script business and whatnot. I only started understanding MUI triggers about 2 weeks ago. It looks like a lot of the pages I was learning from are pretty old (can't say im too surprised).


At this point you might as well learn Jass since you're using so much Custom Script anyway (or better, Lua) :p
maybe I should, I think doing all this GUI stuff has gotten me to a point where I might be able to understand it easier so that's at least good :D


Gotten it working, so thanks as always!
 
Top