• 🏆 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] Replacing items in inventory cancels loop

Status
Not open for further replies.
So, I have an item that should be replaced ("turned off") if the current mana is too low.

Currently when I loop through each inventory slot to check for the correct item, if you have it and enough mana, it drains some mana, else it turns off.
That's the idea of it.

I turn it off by removing it and createing a new one.

The variables:
temp_unit: The unit casting the spell, or spending mana while using spell (channeling)
temp_real5: The mana refund/cost-increase
temp_integer1: The mana-cost of the ability (for that unit, using correct level etc.).
  • Check item types carried by hero etc.
  • ...
  • For each (Integer A) from 1 to 6, do (Actions)
    • Loop - Actions
      • Set temp_item = (Item carried by temp_unit in slot (Integer A))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of temp_item) Equal to Arcane Ring of Amplification (on)
        • Then - Actions
          • Game - Display to (All players) the text: (has item in: + (String((Integer A))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Mana of temp_unit) Less than 2000.00
            • Then - Actions
              • Item - Remove temp_item
              • Hero - Create Arcane Ring of Amplification (off) and give it to temp_unit
            • Else - Actions
              • Custom script: set udg_temp_real5 = udg_temp_real5 - 1.0 * udg_temp_integer1
        • Else - Actions
  • ...
  • Drain mana based on temp_real5
If I have over 2000 mana, the text is displayed (1,2,3,4,5,6).
If I have under 2000 mana, it runs for 1 then stops. 1 is successfully replaced, but it does not continue!
If I throw another spell it runs for 2 then stops. Then 3. Always 1 at the time, instead of all at once! This means, the loop gets broken somehow.

The rest of actions below continue successfully.

Any ideas on how to solve that problem?
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Might have to do something with your use of Integer A.

  • Hero - Create Arcane Ring of Amplification (off) and give it to temp_unit
If that action fires a trigger that uses the Event "A unit acquires an Item", and that trigger uses a For Loop with Integer A, you'll run into issues. Try using a new Integer variable instead of Integer A.

If the problem still happens for some reason, you can try adding the temp_items to an Array of items, and then Loop through and "replace" them after the first Loop.
 
Status
Not open for further replies.
Top