• 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.

It doesn't make any sense...

Status
Not open for further replies.
Level 9
Joined
Apr 19, 2011
Messages
447
Hi everyone.

I don't know if I'm just stupid... Let's see, I have the following trigger:

  • For each (Integer INTEGER) from 1 to 3, do (Actions)
    • Loop - Actions
      • Game - Display to (All players) the text: (String(INTEGER))
It should show in the screen:
1
2
3

Ok, it shows:
1
1
1

Why? It doesn't make sense! But this only happens in the map I'm working on. I opened a fresh new map, tested the trigger, and it behaved as expected. But in my map, it only shows 1, although the trigger should loop from 1 to 3. I don't get what's wrong with it...
Any help will be appreciated.

Kind Regards
 
Hmm , The reason may be one of these :
1- You use INTEGER as a contant ( = 1 ) [## Probably in a JASS script ##]
2- There is a periodic trigger that uses INTEGER and it has INTEGER = 1 (always) .
3- Your map is bugged . :p

1) that cant happen. if its a constant u cant use it in loops as it wont let u.
2) wc3 runs one trigger at a time so this is impossible
3) that is the most likely conclusion if that is his whole trigger.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
[QUOTE
2) wc3 runs one trigger at a time so this is impossible
[/QUOTE]

It's very possible . I use about 2 - 3 periodic triggers in one time . Each Trigger is run form a different source trigger . Like in 2D Engine . So i think you're wrong :D Look at this:
  • Events
    • Map Initialization
  • Actions
    • Trigger - Run LOOP TRIGGER 1 <gen>
  • Events
    • Time - Time elapsed is 0.00 seconds
  • Actions
    • Trigger - Run LOOP TRIGGER 2 <gen>
  • LOOP TRIGGER 1
  • Events
    • Time - Every 0.03 seconds
  • Actions
    • Do Nothing
  • LOOP TRIGGER 2
  • Events
    • Time - Every 0.03 seconds
  • Actions
    • Do Nothing
 
Well You may well be right , If we use 0.03 for both triggers . One trigger completes its delay (0.03) , The other trigger runs ( it completes its delay 0.03) the first trigger runs again . We asume that they are both run at the same time .

exactly. thats y its so important to make sure all triggers are very efficient. u can test this by running multiple triggers with the same integer in a loop from 1 to 10 to display the integer value. they will always display from 1 to 10 then 1 to 10 and so on.
 
Level 9
Joined
Apr 19, 2011
Messages
447
Thank you for the answers.
The whole trigger is a lot bigger. I'm right now trying to fix issues in a spell, and I was debugging the trigger with text messages. I found that a loop similar to the one I posted only shows 1 (as I said before). This is the trigger:

NOTE: In the trigger, there are various "for" loops. The problematic ones are marked with "XXXXXXXX" comments.
  • Defragmentation Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Casters_Defragmentation and do (Actions)
        • Loop - Actions
          • Set Key = (Key (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 0 of Key from Defragmentation) Lesser than 1.00
            • Then - Actions
              • Hashtable - Save ((Load 0 of Key from Defragmentation) + 0.03) as 0 of Key in Defragmentation
              • Set TempLoc = (Position of (Picked unit))
              • Set TempReal = ((Load 0 of Key from Defragmentation) x 150.00)
              • Set TempInteger = (Load 6 of Key from Defragmentation)
              • -------- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --------
              • -------- I've checked the value of TempInteger with text messages, it's 3, 5 or 7 (it depends of the level of the spell). This loop is ALWAYS stuck in 1, as I said in my first post. --------
              • For each (Integer INTEGER) from 1 to TempInteger, do (Actions)
                • Loop - Actions
                  • Set TempUnit = (Load INTEGER of Key in Defragmentation)
                  • Set TempLoc02 = (TempLoc offset by TempReal towards (90.00 + ((360.00 / (Load 6 of Key from Defragmentation)) x ((Real(INTEGER)) - 1.00))) degrees)
                  • Custom script: call SetUnitX(udg_TempUnit, GetLocationX(udg_TempLoc02))
                  • Custom script: call SetUnitY(udg_TempUnit, GetLocationY(udg_TempLoc02))
                  • Custom script: call RemoveLocation(udg_TempLoc02)
              • Custom script: call RemoveLocation(udg_TempLoc)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 0 of Key from Defragmentation) Lesser than ((Load 7 of Key from Defragmentation) + 1.00)
                • Then - Actions
                  • Hashtable - Save ((Load 0 of Key from Defragmentation) + 0.03) as 0 of Key in Defragmentation
                  • Set TempLoc = (Position of (Picked unit))
                  • For each (Integer INTEGER) from 1 to (Load 6 of Key from Defragmentation), do (Actions)
                    • Loop - Actions
                      • Set TempUnit = (Load INTEGER of Key in Defragmentation)
                      • Set TempLoc02 = (Position of TempUnit)
                      • Set TempLoc03 = (TempLoc offset by 150.00 towards ((Angle from TempLoc to TempLoc02) + 10.00) degrees)
                      • Custom script: call SetUnitX(udg_TempUnit, GetLocationX(udg_TempLoc03))
                      • Custom script: call SetUnitY(udg_TempUnit, GetLocationY(udg_TempLoc03))
                      • Set TempGroup = (Units within 75.00 of TempLoc03)
                      • Set TempUnit = (Picked unit)
                      • Unit Group - Pick every unit in TempGroup and do (Actions)
                        • Loop - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Owner of (Picked unit)) is an enemy of (Owner of TempUnit)) Equal to True
                            • Then - Actions
                              • Unit - Cause TempUnit to damage (Picked unit), dealing ((Load 8 of Key from Defragmentation) x 0.03) damage of attack type Spells and damage type Normal
                              • Hashtable - Save ((Load 8 of Key from Defragmentation) x 0.03) as 10 of Key in Defragmentation
                            • Else - Actions
                              • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + ((Load 8 of Key from Defragmentation) x 0.03))
                              • Hashtable - Save ((Load 8 of Key from Defragmentation) x 0.03) as 11 of Key in Defragmentation
                      • Custom script: call DestroyGroup(udg_TempGroup)
                      • Custom script: call RemoveLocation(udg_TempLoc02)
                      • Custom script: call RemoveLocation(udg_TempLoc03)
                  • Custom script: call RemoveLocation(udg_TempLoc)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Load 0 of Key from Defragmentation) Lesser than ((Load 7 of Key from Defragmentation) + 2.00)
                    • Then - Actions
                      • Hashtable - Save ((Load 0 of Key from Defragmentation) + 0.03) as 0 of Key in Defragmentation
                      • Set TempLoc = (Position of (Picked unit))
                      • Set TempReal = ((((Load 0 of Key from Defragmentation) - ((Load 7 of Key from Defragmentation) + 1.00)) / 0.03) x (150.00 x 0.03))
                      • Set TempInteger = (Load 6 of Key from Defragmentation)
                      • -------- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --------
                      • -------- I've checked the value of TempInteger with text messages, it's 3, 5 or 7 (it depends of the level of the spell). This loop is ALWAYS stuck in 1, as I said in my first post. --------
                      • For each (Integer INTEGER) from 1 to TempInteger, do (Actions)
                        • Loop - Actions
                          • Set TempUnit = (Load INTEGER of Key in Defragmentation)
                          • Set TempLoc02 = (Position of TempUnit)
                          • Set TempLoc03 = (TempLoc02 offset by TempReal towards ((Angle from TempLoc02 to TempLoc) + ((360.00 / (Load 6 of Key from Defragmentation)) x ((Real(INTEGER)) - 1.00))) degrees)
                          • Custom script: call SetUnitX(udg_TempUnit, GetLocationX(udg_TempLoc02))
                          • Custom script: call SetUnitY(udg_TempUnit, GetLocationY(udg_TempLoc02))
                          • Custom script: call RemoveLocation(udg_TempLoc02)
                          • Custom script: call RemoveLocation(udg_TempLoc03)
                      • Custom script: call RemoveLocation(udg_TempLoc)
                    • Other - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Load 12 of Key from Defragmentation) Equal to False
                        • Then - Actions
                          • Hashtable - Save True as 12 of Key in Defragmentation
                          • Set TempInteger = (load 6 of Key from Defragmentation)
                          • For each (Integer INTEGER) from 1 to TempInteger, do (Actions)
                            • Loop - Actions
                              • Unit - Remove (Load INTEGER of Key in Defragmentation) from the game
                          • Unit - Add SB (Defragmentation) to (Picked unit)
                          • Sound - Stop MagicLariatLoop1 <gen> After fade out
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Level of Ability_Defragmentation for (Picked unit)) Equal to 1
                            • Then - Actions
                              • Set Defragmentation_Bonus[1] = DEFRAGMENTATION Attack rate (+15%)
                              • Set Defragmentation_Bonus[2] = DEFRAGMENTATION Attack rate (+10%)
                              • Set Defragmentation_Bonus[3] = DEFRAGMENTATION Attack rate (+5%)
                              • Set Defragmentation_Bonus[4] = DEFRAGMENTATION Attack rate (-5%)
                              • Set Defragmentation_Bonus[5] = DEFRAGMENTATION Attack rate (-10%)
                              • Set Defragmentation_Bonus[6] = DEFRAGMENTATION Attack rate (-15%)
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (Level of Ability_Defragmentation for (Picked unit)) Equal to 2
                                • Then - Actions
                                  • Set Defragmentation_Bonus[1] = DEFRAGMENTATION Attack rate (+25%)
                                  • Set Defragmentation_Bonus[2] = DEFRAGMENTATION Attack rate (+15%)
                                  • Set Defragmentation_Bonus[3] = DEFRAGMENTATION Attack rate (+5%)
                                  • Set Defragmentation_Bonus[4] = DEFRAGMENTATION Attack rate (-5%)
                                  • Set Defragmentation_Bonus[5] = DEFRAGMENTATION Attack rate(-15%)
                                  • Set Defragmentation_Bonus[6] = DEFRAGMENTATION Attack rate (-25%)
                                • Else - Actions
                                  • Set Defragmentation_Bonus[1] = DEFRAGMENTATION Attack rate (+40%)
                                  • Set Defragmentation_Bonus[2] = DEFRAGMENTATION Attack rate (+30%)
                                  • Set Defragmentation_Bonus[3] = DEFRAGMENTATION Attack rate (+15%)
                                  • Set Defragmentation_Bonus[4] = DEFRAGMENTATION Attack rate (-15%)
                                  • Set Defragmentation_Bonus[5] = DEFRAGMENTATION Attack rate (-30%)
                                  • Set Defragmentation_Bonus[6] = DEFRAGMENTATION Attack rate (-40%)
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Load 10 of Key from Defragmentation) Higher than (Load 11 of Key from Defragmentation)
                            • Then - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (Load 10 of Key from Defragmentation) Higher than (0.75 x ((Load 10 of Key from Defragmentation) + (Load 11 of Key from Defragmentation)))
                                • Then - Actions
                                  • Player - Enable Defragmentation_Bonus[1] for (Owner of (Picked unit))
                                • Else - Actions
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • (Load 10 of Key from Defragmentation) Higher than (0.50 x ((Load 10 of Key from Defragmentation) + (Load 11 of Key from Defragmentation)))
                                    • Then - Actions
                                      • Player - Enable Defragmentation_Bonus[2] for (Owner of (Picked unit))
                                    • Else - Actions
                                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                        • If - Conditions
                                          • (Load 10 of Key from Defragmentation) Higher than (0.25 x ((Load 10 of Key from Defragmentation) + (Load 11 of Key from Defragmentation)))
                                        • Then - Actions
                                          • Player - Enable Defragmentation_Bonus[3] for (Owner of (Picked unit))
                                        • Else - Actions
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (Load 11 of Key from Defragmentation) Higher than (0.75 x ((Load 10 of Key from Defragmentation) + (Load 11 of Key from Defragmentation)))
                                • Then - Actions
                                  • Player - Enable Defragmentation_Bonus[4] for (Owner of (Picked unit))
                                • Else - Actions
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • (Load 11 of Key from Defragmentation) Higher than (0.50 x ((Load 10 of Key from Defragmentation) + (Load 11 of Key from Defragmentation)))
                                    • Then - Actions
                                      • Player - Enable Defragmentation_Bonus[5] for (Owner of (Picked unit))
                                    • Else - Actions
                                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                        • If - Conditions
                                          • (Load 11 of Key from Defragmentation) Higher than (0.25 x ((Load 10 of Key from Defragmentation) + (Load 11 of Key from Defragmentation)))
                                        • Then - Actions
                                          • Player - Enable Defragmentation_Bonus[6] for (Owner of (Picked unit))
                                        • Else - Actions
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Load 0 of Key from Defragmentation) Lesser than ((Load 7 of Key from Defragmentation) + (2.00 + (Load 9 of Key from Defragmentation)))
                            • Then - Actions
                              • Hashtable - Save ((Load 0 of Key from Defragmentation) + 0.03) as 0 of Key in Defragmentation
                            • Else - Actions
                              • Player - Disable DEFRAGMENTATION Attack rate (+10%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (+15%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (+25%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (+30%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (+40%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (+5%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (-10%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (-15%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (-25%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (-30%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (-40%) for (Owner of (Picked unit))
                              • Player - Disable DEFRAGMENTATION Attack rate (-5%) for (Owner of (Picked unit))
                              • Unit Group - Remove (Picked unit) from Casters_Defragmentation
                              • Hashtable - Clear all child hashtables of child Key in Defragmentation
Basicly, the loops that I marked with the comments are always stuck in 1. I even tried to make them loop from 1 to 3, for example (instead of looping from 1 to TempInteger), and they are still stuck in 1. All the other loops in the trigger work fine. I don't understand the reason. Maybe there's something in the trigger that's messing up the loops (it wouldn't surprise me, I already expect that...).

Hopefully, this trigger is from a test map I'm using to create and test the spells before implementing them into the real map, so I won't lose too much if the map is bugged, but I hope that's not the case.
Any ideas?

Kind Regards
 
Level 8
Joined
Oct 12, 2011
Messages
483
You're nesting for loops using the same integer variables... Nested for loops must use different variables or else they'll interfere with each other.

  • For each (Integer INTEGER) from 1 to 10, do (Actions)
    • Loop - Actions
      • Game - Display to (All Players) the text: Herp
      • For each (Integer INTEGER) from 1 to 20, do (Actions)
        • Loop - Actions
          • Game - Display to (All Players) the text: Derp
This will result in 1 Herp and 20 Derps, since when the Derp loop is through, INTEGER will already be at 20, and so will already be greater than the 10 for the outer loop.
 
Level 9
Joined
Apr 19, 2011
Messages
447
You're nesting for loops using the same integer variables... Nested for loops must use different variables or else they'll interfere with each other.

  • For each (Integer INTEGER) from 1 to 10, do (Actions)
    • Loop - Actions
      • Game - Display to (All Players) the text: Herp
      • For each (Integer INTEGER) from 1 to 20, do (Actions)
        • Loop - Actions
          • Game - Display to (All Players) the text: Derp
This will result in 1 Herp and 20 Derps, since when the Derp loop is through, INTEGER will already be at 20, and so will already be greater than the 10 for the outer loop.

Nested loops? Where? I don't see any in the trigger I posted...
:eekani:

EDIT: Even if I'm nesting loops, I don't think that's the problem. I tested the trigger while using a different variable for each of the loops, and the result is the same.


Kind Regards
 
Level 9
Joined
Apr 19, 2011
Messages
447
I attached the map. The map was using some custom resources, all of them imported in a campaign. It was easier for me to just delete the heaviest imports and the irrelevant maps of the campaign, and upload it with just the map I'm testing the spells on.

Basicly, the campaign I attached contains the map with the hero and the triggered spells. There are a total of 4 triggered spells, but the one that's relevant to this thread is the "Defragmentation" spell. There's a comment called "---------- Defragmentation ----------". If you click it, you'll see to the right some explanations about what exactly happens with the spell, and where are the problematic loops.

There are some things that are in spanish (like the tooltip of the spell), but I don't think that should be a problem, I think the relevant things are in english.

Thank you in advance.

Kind Regards
 

Attachments

  • TEST.w3n
    6.8 MB · Views: 79
Status
Not open for further replies.
Top