• 🏆 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] Help, Weird loop

Status
Not open for further replies.
Level 3
Joined
Oct 8, 2017
Messages
20
Full
  • A looping Trigger
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Custom script: local integer i
      • Custom script: local boolean recycle = false
      • Custom script: call IncreaseArray()
      • Custom script: set i = udg_Increasing_Array
      • Custom script: set udg_TempInt = i
      • For each (Integer C[TempInt]) from 1 to VB_Index, do (Actions)
        • Loop - Actions
          • Custom script: set udg_TempInt = udg_C[i]
          • Game - Display to (All players) the text: (VB_Index = + (String(VB_Index)))
          • Game - Display to (All players) the text: (Current Loop = + (String(TempInt)))
          • Custom script: set recycle = false
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (VB_Target[TempInt] is alive) Equal to True
            • Then - Actions
              • Set p1 = (Position of VB_Missile[TempInt])
              • Set p2 = (Position of VB_Target[TempInt])
              • Set TempPoint = (p1 offset by 15.00 towards (Angle from p1 to p2) degrees)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between p1 and p2) Less than or equal to 20.00
                • Then - Actions
                  • Unit - Cause VB_Source[TempInt] to damage VB_Target[TempInt], dealing VB_Damage[TempInt] damage of attack type Spells and damage type Normal
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • VB_RestoreMana[TempInt] Equal to True
                    • Then - Actions
                      • Unit - Set mana of VB_Source[TempInt] to ((Percentage mana of VB_Source[TempInt]) + 16.00)%
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (VB_Target[TempInt] has buff Shadow Word: Pain (Buff)) Equal to True
                        • Then - Actions
                          • For each (Integer i_integer2) from 1 to BS_Index2, do (Actions)
                            • Loop - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • BS_Buff[i_integer2] Equal to Shadow Word: Pain (Buff)
                                • Then - Actions
                                  • Set BS_Buff_Duration[i_integer2] = (BS_Buff_Duration[i_integer2] + 1.50)
                                • Else - Actions
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (VB_Target[TempInt] has buff Vampiric Touch (Buff)) Equal to True
                        • Then - Actions
                          • For each (Integer i_integer2) from 1 to BS_Index2, do (Actions)
                            • Loop - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • BS_Buff[i_integer2] Equal to Vampiric Touch (Buff)
                                • Then - Actions
                                  • Set BS_Buff_Duration[i_integer2] = (BS_Buff_Duration[i_integer2] + 1.50)
                                • Else - Actions
                        • Else - Actions
                    • Else - Actions
                  • -------- ---- --------
                  • Custom script: set recycle = true
                  • -------- ---- --------
                • Else - Actions
                  • Unit - Move VB_Missile[TempInt] instantly to TempPoint, facing (Angle from p1 to p2) degrees
              • Custom script: call RemoveLocation(udg_TempPoint)
              • Custom script: call RemoveLocation(udg_p1)
              • Custom script: call RemoveLocation(udg_p2)
            • Else - Actions
              • Custom script: set recycle = true
          • -------- ---- --------
          • Special Effect - Destroy VB_eff[TempInt]
          • Unit - Remove VB_Missile[TempInt] from the game
          • Custom script: if ( recycle == true ) then
          • Custom script: set recycle = false
          • Custom script: if ( udg_TempInt == udg_VB_Index ) then
          • Custom script: if ( true ) then
          • Special Effect - Destroy VB_eff[TempInt]
          • Unit - Remove VB_Missile[TempInt] from the game
          • Set VB_Missile[VB_Index] = No unit
          • Set VB_Source[VB_Index] = No unit
          • Set VB_Target[VB_Index] = No unit
          • Set VB_Damage[VB_Index] = 0.00
          • Set VB_RestoreMana[VB_Index] = False
          • Set VB_Index = (VB_Index - 1)
          • Custom script: else
          • Special Effect - Destroy VB_eff[TempInt]
          • Unit - Remove VB_Missile[TempInt] from the game
          • Set VB_eff[TempInt] = VB_eff[VB_Index]
          • Set VB_Missile[TempInt] = VB_Missile[VB_Index]
          • Set VB_Source[TempInt] = VB_Source[VB_Index]
          • Set VB_Target[TempInt] = VB_Target[VB_Index]
          • Set VB_RestoreMana[TempInt] = VB_RestoreMana[VB_Index]
          • Set VB_Damage[TempInt] = VB_Damage[VB_Index]
          • -------- ---- --------
          • Set VB_Missile[VB_Index] = No unit
          • Set VB_Source[VB_Index] = No unit
          • Set VB_Target[VB_Index] = No unit
          • Set VB_Damage[VB_Index] = 0.00
          • Set VB_RestoreMana[VB_Index] = False
          • -------- ---- --------
          • Set VB_Index = (VB_Index - 1)
          • Custom script: set udg_C[i] = udg_C[i] - 1
          • Custom script: endif
          • Custom script: endif
          • -------- ---- --------
          • Custom script: set udg_TempInt = i
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • VB_Index Equal to 0
            • Then - Actions
              • Trigger - Turn off (This trigger)
              • Custom script: exitwhen true
            • Else - Actions
Pointed
  • A looping Trigger
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Custom script: local integer i
      • Custom script: local boolean recycle = false
      • Custom script: call IncreaseArray() // increases increasing array by 1, up to 8192
      • Custom script: set i = udg_Increasing_Array
      • Custom script: set udg_TempInt = i // to work in gui
      • For each (Integer C[TempInt]) from 1 to VB_Index, do (Actions)
        • Loop - Actions
          • Custom script: set udg_TempInt = udg_C[i]
          • Game - Display to (All players) the text: (VB_Index = + (String(VB_Index))) // debug
          • Game - Display to (All players) the text: (Current Loop = + (String(TempInt))) // debug
          • Custom script: set recycle = false
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (VB_Target[TempInt] is alive) Equal to True
            • Then - Actions
              • Set p1 = (Position of VB_Missile[TempInt])
              • Set p2 = (Position of VB_Target[TempInt])
              • Set TempPoint = (p1 offset by 15.00 towards (Angle from p1 to p2) degrees)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between p1 and p2) Less than or equal to 20.00
                • Then - Actions
                  • Unit - Cause VB_Source[TempInt] to damage VB_Target[TempInt], dealing VB_Damage[TempInt] damage of attack type Spells and damage type Normal
                  • -------- ---- --------
                  • Custom script: set recycle = true
                  • -------- ---- --------
                • Else - Actions
                  • Unit - Move VB_Missile[TempInt] instantly to TempPoint, facing (Angle from p1 to p2) degrees
              • Custom script: call RemoveLocation(udg_TempPoint)
              • Custom script: call RemoveLocation(udg_p1)
              • Custom script: call RemoveLocation(udg_p2)
            • Else - Actions
              • Custom script: set recycle = true
          • -------- ---- --------
          • Special Effect - Destroy VB_eff[TempInt]
          • Unit - Remove VB_Missile[TempInt] from the game
          • Custom script: if ( recycle == true ) then
          • Custom script: set recycle = false
          • Custom script: if ( udg_TempInt == udg_VB_Index ) then
          • Custom script: if ( true ) then
          • Special Effect - Destroy VB_eff[TempInt]
          • Unit - Remove VB_Missile[TempInt] from the game
          • Set VB_Missile[VB_Index] = No unit
          • Set VB_Source[VB_Index] = No unit
          • Set VB_Target[VB_Index] = No unit
          • Set VB_Damage[VB_Index] = 0.00
          • Set VB_RestoreMana[VB_Index] = False
          • Set VB_Index = (VB_Index - 1) // somehow this is done 2 times
          • Custom script: else
          • Special Effect - Destroy VB_eff[TempInt]
          • Unit - Remove VB_Missile[TempInt] from the game
          • Set VB_eff[TempInt] = VB_eff[VB_Index]
          • Set VB_Missile[TempInt] = VB_Missile[VB_Index]
          • Set VB_Source[TempInt] = VB_Source[VB_Index]
          • Set VB_Target[TempInt] = VB_Target[VB_Index]
          • Set VB_RestoreMana[TempInt] = VB_RestoreMana[VB_Index]
          • Set VB_Damage[TempInt] = VB_Damage[VB_Index]
          • -------- ---- --------
          • Set VB_Missile[VB_Index] = No unit
          • Set VB_Source[VB_Index] = No unit
          • Set VB_Target[VB_Index] = No unit
          • Set VB_Damage[VB_Index] = 0.00
          • Set VB_RestoreMana[VB_Index] = False
          • -------- ---- --------
          • Set VB_Index = (VB_Index - 1) // somehow this is done 2 times
          • Custom script: set udg_C[i] = udg_C[i] - 1 // somehow this is done 2 times
          • Custom script: endif
          • Custom script: endif
          • -------- ---- --------
          • Custom script: set udg_TempInt = i
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • VB_Index Equal to 0
            • Then - Actions
              • Trigger - Turn off (This trigger)
              • Custom script: exitwhen true
            • Else - Actions
JASS:
function IncreaseArray takes nothing returns nothing
    if ( udg_Increasing_Array == 8192 ) then
        set udg_Increasing_Array = 0
    else
        set udg_Increasing_Array = ( udg_Increasing_Array + 1 )
    endif
endfunction

How it should work

It moves a dummy unit with effect as missile towards a target, whenever it reaches the target (comes to 20 units distance) it should delete the effect and the unit from the current loop index, and set the last index to the current index, and lower the current index and the last index so that the loop continues... but somehow it doesnt......

Solved

for anyone curious
  • VB Missile new
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Custom script: local boolean recycle
      • Custom script: local location p1
      • Custom script: local location p2
      • For each (Integer VB_Index2) from 1 to VB_Index, do (Actions)
        • Loop - Actions
          • Custom script: set recycle = false
          • Custom script: set p1 = GetUnitLoc(udg_VB_Missile[udg_VB_Index2])
          • Custom script: set p2 = GetUnitLoc(udg_VB_Target[udg_VB_Index2])
          • Custom script: set udg_TempPoint = PolarProjectionBJ(p1, 15.00, AngleBetweenPoints(p1, p2))
          • Custom script: if ( ( DistanceBetweenPoints(p1, p2) <= 20.00 ) ) then
          • Custom script: set recycle = true
          • Unit - Cause VB_Source[VB_Index2] to damage VB_Target[VB_Index2], dealing VB_Damage[VB_Index2] damage of attack type Spells and damage type Normal
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • VB_RestoreMana[VB_Index2] Equal to True
            • Then - Actions
              • Unit - Set mana of VB_Source[VB_Index2] to ((Percentage mana of VB_Source[VB_Index2]) + 16.00)%
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (VB_Target[VB_Index2] has buff Shadow Word: Pain (Buff)) Equal to True
                • Then - Actions
                  • For each (Integer i_integer2) from 1 to BS_Index2, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • BS_Buff[i_integer2] Equal to Shadow Word: Pain (Buff)
                        • Then - Actions
                          • Set BS_Buff_Duration[i_integer2] = (BS_Buff_Duration[i_integer2] + 1.50)
                        • Else - Actions
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (VB_Target[VB_Index2] has buff Vampiric Touch (Buff)) Equal to True
                • Then - Actions
                  • For each (Integer i_integer2) from 1 to BS_Index2, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • BS_Buff[i_integer2] Equal to Vampiric Touch (Buff)
                        • Then - Actions
                          • Set BS_Buff_Duration[i_integer2] = (BS_Buff_Duration[i_integer2] + 1.50)
                        • Else - Actions
                • Else - Actions
            • Else - Actions
          • Custom script: else
          • Custom script: call SetUnitPositionLocFacingBJ( udg_VB_Missile[udg_VB_Index2], udg_TempPoint, AngleBetweenPoints(p1, p2) )
          • Custom script: endif
          • Custom script: call RemoveLocation(udg_TempPoint)
          • Custom script: call RemoveLocation(p1)
          • Custom script: call RemoveLocation(p2)
          • -------- ---- --------
          • Custom script: if ( recycle == true ) then
          • Custom script: set recycle = false
          • Custom script: if ( udg_VB_Index2 == udg_VB_Index ) then
          • Special Effect - Destroy VB_eff[VB_Index2]
          • Unit - Remove VB_Missile[VB_Index2] from the game
          • Set VB_Missile[VB_Index] = No unit
          • Set VB_Source[VB_Index] = No unit
          • Set VB_Target[VB_Index] = No unit
          • Set VB_Damage[VB_Index] = 0.00
          • Set VB_RestoreMana[VB_Index] = False
          • Set VB_Index = (VB_Index - 1)
          • Custom script: else
          • Special Effect - Destroy VB_eff[VB_Index2]
          • Unit - Remove VB_Missile[VB_Index2] from the game
          • Set VB_eff[VB_Index2] = VB_eff[VB_Index]
          • Set VB_Missile[VB_Index2] = VB_Missile[VB_Index]
          • Set VB_Source[VB_Index2] = VB_Source[VB_Index]
          • Set VB_Target[VB_Index2] = VB_Target[VB_Index]
          • Set VB_RestoreMana[VB_Index2] = VB_RestoreMana[VB_Index]
          • Set VB_Damage[VB_Index2] = VB_Damage[VB_Index]
          • -------- ---- --------
          • Set VB_Missile[VB_Index] = No unit
          • Set VB_Source[VB_Index] = No unit
          • Set VB_Target[VB_Index] = No unit
          • Set VB_Damage[VB_Index] = 0.00
          • Set VB_RestoreMana[VB_Index] = False
          • -------- ---- --------
          • Set VB_Index = (VB_Index - 1)
          • Set VB_Index2 = (VB_Index2 - 1)
          • Custom script: endif
          • Custom script: endif
          • -------- ---- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • VB_Index Equal to 0
            • Then - Actions
              • Trigger - Turn off (This trigger)
            • Else - Actions
      • Custom script: set p1 = null
      • Custom script: set p2 = null
It was either wrong loop variable or while calling the creation trigger, udg_p1 was already in use, and the missile system was reusing it, or i dont know but it works with local variables
 
Last edited:
Level 3
Joined
Oct 8, 2017
Messages
20
So when i tested this, when multiple missiles are shot, they are traveling as they should, but as soon as they reach the target both VB_Index and the current loop become 1 and only 1 missile continues traveling and hitting the target as it should, the rest just stand there because the index was lost somehow...
 
Level 3
Joined
Oct 8, 2017
Messages
20
This is so weird, i made a completely new map and used all local variables for the points, and its working flawlessly, im going to implement it to my map and see if it will work.
 
Status
Not open for further replies.
Top