• 🏆 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] Buying Abilities - Integer Issues

Status
Not open for further replies.
Level 30
Joined
Jan 31, 2010
Messages
3,551
Hey there. I have red a tutorial () and created the system which allows you to buy abilities from item shops, but I encountered some issues. Whenever I try to buy an ability, the trigger works, but it always gives me one ability - Frost Arrows. I am open for solution on how to make it work.
  • Set Variables
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Skill[0] = Searing Arrows
      • Set Skill[1] = Frost Arrows
      • Set Skill[2] = Black Arrows
      • Set Items[0] = Searing Arrows
      • Set Items[1] = Frost Arrows
      • Set Items[2] = Black Arrows
  • Acquires Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Powerup
    • Actions
      • For each (Integer A) from 0 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Items[(Integer A)] Equal to (Item-type of (Item being manipulated))
              • (Level of Skill[(Player number of (Owner of (Triggering unit)))] for (Triggering unit)) Less than 1
            • Then - Actions
              • Game - Display to (All players) for 6.00 seconds the text: ((Name of (Owner of (Triggering unit))) + ( has bought + (Name of (Item being manipulated))))
              • Unit - Add Skill[(Player number of (Owner of (Triggering unit)))] to (Triggering unit)
              • Skip remaining actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Skill[(Player number of (Owner of (Triggering unit)))] for (Triggering unit)) Less than 20
                • Then - Actions
                  • Game - Display to (All players) for 6.00 seconds the text: ((Name of (Owner of (Triggering unit))) + ( upgraded + (Name of (Item being manipulated))))
                  • Unit - Set level of Skill[(Player number of (Owner of (Triggering unit)))] for (Triggering unit) to ((Level of Skill[(Player number of (Owner of (Triggering unit)))] for (Triggering unit)) + 1)
                  • Skip remaining actions
                • Else - Actions
                  • Game - Display to (All players) for 6.00 seconds the text: Skill is at maximum...
                  • Skip remaining actions
Since this is taken entirely from this tutorial: http://www.hiveworkshop.com/forums/trigger-gui-editor-tutorials-279/buying-abilitys-37965/, maybe someone should contact the current Tutorial Moderator in order to fix that.
*I contacted the moderator.
 
Level 30
Joined
Jan 31, 2010
Messages
3,551
Okay, replaced as you said. But now, new problems appear. When I try to buy Searing Arrows, it adds me that skill, which is fine. But upon purchasing it again to gain upgrade, nothing happens. However, when I try to buy the two other skills (Black Arrows and Frozen Arrows), the Searing Arrows is upgraded instead.
  • Acquires Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Powerup
    • Actions
      • For each (Integer A) from 0 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Items[(Integer A)] Equal to (Item-type of (Item being manipulated))
              • (Level of Skill[(Integer A)] for (Triggering unit)) Less than 1
            • Then - Actions
              • Game - Display to (All players) for 6.00 seconds the text: ((Name of (Owner of (Triggering unit))) + ( has bought + (Name of (Item being manipulated))))
              • Unit - Add Skill[(Integer A)] to (Triggering unit)
              • Skip remaining actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Skill[(Player number of (Owner of (Triggering unit)))] for (Triggering unit)) Less than 20
                • Then - Actions
                  • Game - Display to (All players) for 6.00 seconds the text: ((Name of (Owner of (Triggering unit))) + ( upgraded + (Name of (Item being manipulated))))
                  • Unit - Set level of Skill[(Integer A)] for (Triggering unit) to ((Level of Skill[(Integer A)] for (Triggering unit)) + 1)
                  • Skip remaining actions
                • Else - Actions
                  • Game - Display to (All players) for 6.00 seconds the text: Skill is at maximum...
                  • Skip remaining actions
 
Ah well, how blind I was. See, the first condition(s) check if the item-type is equal to Items[(IntegerA)] and if the unit doesn't have this ability. In the else, it means that neither of them is true, that's why it didn't add the other two abilities, because the engine "thought" that it would apply the upgrading conditions only when the Item-type of (Item being manipulated) was not equal to Items[(IntegerA)]. You had better be cautious with separate if/then/else's.
Make your actions look like this:
  • Actions
    • For each (Integer A) from 0 to 2, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Items[(Integer A)] Equal to (Item-type of (Item being manipulated))
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Level of Skill[(Integer A)] for (Triggering unit)) Less than 1
              • Then - Actions
                • Game - Display to (All players) for 6.00 seconds the text: ((Name of (Owner of (Triggering unit))) + ( has bought + (Name of (Item being manipulated))))
                • Unit - Add Skill[(Integer A)] to (Triggering unit)
                • Skip remaining actions
              • Else - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Level of Skill[(Integer A)] for (Triggering unit)) Less than 20
                  • Then - Actions
                    • Game - Display to (All players) for 6.00 seconds the text: ((Name of (Owner of (Triggering unit))) + ( upgraded + (Name of (Item being manipulated))))
                    • Unit - Set level of Skill[(Integer A)] for (Triggering unit) to ((Level of Skill[(Integer A)] for (Triggering unit)) + 1)
                    • Skip remaining actions
                  • Else - Actions
                    • Game - Display to (All players) for 6.00 seconds the text: Skill is at maximum...
                    • Skip remaining actions
          • Else - Actions
It was a matter of an additional if/then/else statement.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Simple logic error with the if/then/else.

  • Acquires Item
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Powerup
    • Actions
      • For each (Integer A) from 0 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Items[(Integer A)] Equal to (Item-type of (Item being manipulated))
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Skill[(Integer A)] for (Triggering unit)) Less than 1
                • Then - Actions
                  • Game - Display to (All players) for 6.00 seconds the text: ((Name of (Owner of (Triggering unit))) + ( has bought + (Name of (Item being manipulated))))
                  • Unit - Add Skill[(Integer A)] to (Triggering unit)
                  • Skip remaining actions
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Level of Skill[(Integer A)] for (Triggering unit)) Less than 20
                    • Then - Actions
                      • Game - Display to (All players) for 6.00 seconds the text: ((Name of (Owner of (Triggering unit))) + ( upgraded + (Name of (Item being manipulated))))
                      • Unit - Set level of Skill[(Integer A)] for (Triggering unit) to ((Level of Skill[(Integer A)] for (Triggering unit)) + 1)
                      • Skip remaining actions
                    • Else - Actions
                      • Game - Display to (All players) for 6.00 seconds the text: Skill is at maximum...
                      • Skip remaining actions
            • Else - Actions
 
Last edited:
Status
Not open for further replies.
Top