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

Boolean changes to true somewhere

Status
Not open for further replies.
Level 5
Joined
Sep 27, 2011
Messages
141
  • Actions
    • Set Temp_Unit = (Triggering unit)
    • Set Player = (Owner of Temp_Unit)
    • Set Temp_Int3 = (Player number of Player)
    • Set Resource_Unit = (Unit-type((String((Issued order)))))
    • Custom script: set udg_Temp_Int2 = udg_Resource_Unit
    • Set Temp_Boolean = True
    • -------- Check Unit Costs --------
    • For each (Integer Temp_Int) from 1 to Number_Of_Resources, do (Actions)
      • Loop - Actions
        • Set Unit_Resource_Cost = (Load Temp_Int of Temp_Int2 from Unit_Costs_Table)
        • Set Player_Resources = (Load Temp_Int3 of Temp_Int from Player_Resources_Table)
        • Set Resources_Value = (Integer((Substring(Player_Resources, ((Length of Resources_Contained[Temp_Int]) + 1), (Length of Player_Resources)))))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Unit_Resource_Cost Greater than Resources_Value
          • Then - Actions
            • Set Temp_Boolean = False
          • Else - Actions
    • -------- Temp_Boolean is true even after being set to false i checked --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Boolean Equal to True
        • Then - Actions
          • For each (Integer Temp_Int) from 1 to Number_Of_Resources, do (Actions)
            • Loop - Actions
              • Set Unit_Resource_Cost = (Load Temp_Int of Temp_Int2 from Unit_Costs_Table)
              • Set Player_Resources = (Load Temp_Int3 of Temp_Int from Player_Resources_Table)
              • Set Resources_Value = (Integer((Substring(Player_Resources, ((Length of Resources_Contained[Temp_Int]) + 1), (Length of Player_Resources)))))
              • Set Resources_Value = (Resources_Value - Unit_Resource_Cost)
              • Set Player_Resources = (Resources_Contained[Temp_Int] + (String(Resources_Value)))
              • Hashtable - Save Player_Resources as Temp_Int3 of Temp_Int in Player_Resources_Table
        • Else - Actions
          • Custom script: call IssueImmediateOrderById( udg_Temp_Unit, 851976 )
          • Set Players = (Player group(Player))
          • Game - Display to tempForce the text: Not Enough Resources
          • Custom script: call DestroyForce(udg_Players)
My problem is that somewhere after the Temp_Boolean has been set back to false it changes back to true for the final if condition and i don't know what the problem is can someone please help. Other information the order id is cancel, there are no conditions and the event is when a unit is issued an order with no target. Thanks.
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Your trigger's formatting seems to be off - I assume the first If/Then/Else is inside the loop?

Not that that's your problem, just helps us to read it easier.

One thing you can try, is to replace the boolean with an integer. Start it off at 0, increase by 1 instead of setting to true, and for condition just check if it is greater than 0.
 
Level 5
Joined
Sep 27, 2011
Messages
141
  • Actions
    • Custom script: local integer i
    • Custom script: set i = 0
    • Set Temp_Unit = (Triggering unit)
    • Set Player = (Owner of Temp_Unit)
    • Set Temp_Int3 = (Player number of Player)
    • Set Resource_Unit = (Unit-type((String((Issued order)))))
    • Custom script: set udg_Temp_Int2 = udg_Resource_Unit
    • Set Temp_Boolean = True
    • -------- Check Unit Costs --------
    • For each (Integer Temp_Int) from 1 to Number_Of_Resources, do (Actions)
      • Loop - Actions
        • Set Unit_Resource_Cost = (Load Temp_Int of Temp_Int2 from Unit_Costs_Table)
        • Set Player_Resources = (Load Temp_Int3 of Temp_Int from Player_Resources_Table)
        • Set Resources_Value = (Integer((Substring(Player_Resources, ((Length of Resources_Contained[Temp_Int]) + 1), (Length of Player_Resources)))))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Unit_Resource_Cost Greater than Resources_Value
          • Then - Actions
            • Custom script: set i = i + 1
          • Else - Actions
    • Custom script: if i == 0 then
    • For each (Integer Temp_Int) from 1 to Number_Of_Resources, do (Actions)
      • Loop - Actions
        • Set Unit_Resource_Cost = (Load Temp_Int of Temp_Int2 from Unit_Costs_Table)
        • Set Player_Resources = (Load Temp_Int3 of Temp_Int from Player_Resources_Table)
        • Set Resources_Value = (Integer((Substring(Player_Resources, ((Length of Resources_Contained[Temp_Int]) + 1), (Length of Player_Resources)))))
        • Set Resources_Value = (Resources_Value - Unit_Resource_Cost)
        • Set Player_Resources = (Resources_Contained[Temp_Int] + (String(Resources_Value)))
        • Hashtable - Save Player_Resources as Temp_Int3 of Temp_Int in Player_Resources_Table
    • Custom script: else
    • Custom script: call IssueImmediateOrderById( udg_Temp_Unit, 851976 )
    • Set Players = (Player group(Player))
    • Game - Display to tempForce the text: Not Enough Resource...
    • Custom script: call DestroyForce(udg_Players)
    • Custom script: endif
    • Custom script: set i = 0
Sorry i took so long to reply I tried this but it still wont work resources are now reduced when they are above 0 but you can still train the unit when you have 0 and neither the message is displayed and i don't think the order is issued as that should cancel it i think. Edit to rulerofiron99 im trying to make this as i dont think your system can handle more than 1 resource at the same time and if it can please tell me how.
 
Level 5
Joined
Sep 27, 2011
Messages
141
I know where it changed to true now i figured that out not long after posting but it didn't help and i don't know why it changes or why the trigger doesn't work i'm pretty sure it changes to true after the loop in which it is set to false but even using integers it doesn't seem to work. EDIT: Don't worry i found another way around the problem so thanks anyway everybody.
 
Status
Not open for further replies.
Top