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

[Solved] Something inside my loop isn't working

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Hey there.

I was wondering if anyone knows what could be the problem.
I made a loop, and for some reason it's not corresponding correctly and it might even be an infinite loop, but I don't see why.

The only debug messages that show up ingame are "passed the spellcheck" and "inside loop:". So I know that the code doesn't get beyond the loop for some reason...

Here's my code:

JASS:
private function Actions takes nothing returns boolean
    local integer SpellId = GetSpellAbilityId()
    local unit u = GetTriggerUnit()
    local integer id = GetUnitId(u)
    local player p = GetOwningPlayer(u)
    local integer x = Unit_X[id]
    local integer y = Unit_Y[id]
    local group g
    local unit t
    local integer id2
    local boolean check = true
    local integer spot

    
    /// Summon Bear ///
    if SpellId == 'A007' then
    
        call BJDebugMsg("passed the spellcheck")
        
        set g = NewGroup()
        call GroupEnumUnitsInRect(g, Field[x][y], null)
        set t = FirstOfGroup(g)
        set id2 = GetUnitId(t)
        loop
        exitwhen t == null
            call BJDebugMsg("inside loop:")
            if GetUnitTypeId(t) != 'H025' and GetUnitTypeId(t) != 'H024' then
                set check = false
                call BJDebugMsg("unit is not h025 or h024")
            endif
            if Unit_Reg_Spot[id2] > 5 then
                set check = false
                call BJDebugMsg("unit reg spot is > 5")
            elseif Unit_Reg_Spot[id2] >= spot then
                set spot = Unit_Reg_Spot[id2]
                call BJDebugMsg("Spot = "+I2S(spot))
            endif
            
            call GroupRemoveUnit(g, t)
            set t = FirstOfGroup(g)
            set id2 = GetUnitId(t)
            if t == null then
                call BJDebugMsg("t = null")
            endif
        endloop
        call ReleaseGroup(g)
        call BJDebugMsg("released the group")
        
        if check == true then
            call BJDebugMsg("check = true")
            if spot == 2 then
                set spot = 1
            endif
            set t = CreateUnit(p, 'H025', GetRectCenterX(Field[x][y]), GetRectCenterY(Field[x][y]),270. - (I2R(id)*180.))
            set Unit_Reg_Size[GetUnitId(t)] = 6
            set Unit_Reg_Size[id] = 6
            set Unit_Reg_Spot[GetUnitId(t)] = spot
            set Unit_Reg_Spot[id] = 2
            set Unit_Swimming[GetUnitId(t)] = true
            set Unit_X[GetUnitId(t)] = x
            set Unit_Y[GetUnitId(t)] = y
            set Unit_Steps[GetUnitId(t)] = GetHeroInt(t, true)
            call UnitLineUp(t)
        endif
        
    endif
    
    set u = null
    set t = null
    set p = null

    return false
endfunction
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Add more debug messages to find out which line halts it.

What is Unit_Reg_Spot[id2] and is it set up properly?

Unit_Reg_Spot[ Unit Id ] is an integer that displays his number in a certain rect. The units are grouped up in regiments and each unit in a regiment has a spot, so an identical number (and position) within the rect.

Unit_Reg_Size[ Unit id ] will display the maximum amount of units possible to stand in one of those rects.

It is set up properly, I checked that a few times now.

JASS:
private function Actions takes nothing returns boolean
    local integer SpellId = GetSpellAbilityId()
    local unit u = GetTriggerUnit()
    local integer id = GetUnitId(u)
    local player p = GetOwningPlayer(u)
    local integer x = Unit_X[id]
    local integer y = Unit_Y[id]
    local group g
    local unit t
    local integer id2
    local boolean check = true
    local integer spot

    
    /// Summon Bear ///
    if SpellId == 'A007' then
    
        call BJDebugMsg("passed the spellcheck")
        
        set g = NewGroup()
        call GroupEnumUnitsInRect(g, Field[x][y], null)
        set t = FirstOfGroup(g)
        set id2 = GetUnitId(t)
        loop
        exitwhen t == null
            call BJDebugMsg("inside loop:")
            if GetUnitTypeId(t) != 'H025' and GetUnitTypeId(t) != 'H024' then
                set check = false
                call BJDebugMsg("unit is not h025 or h024")
            endif
            call BJDebugMsg("line A")
            if Unit_Reg_Spot[id2] > 5 then
                set check = false
                call BJDebugMsg("unit reg spot is > 5")
            elseif Unit_Reg_Spot[id2] >= spot then
                call BJDebugMsg("Line B")
                set spot = Unit_Reg_Spot[id2]
                call BJDebugMsg("Spot = "+I2S(spot))
            endif
            call BJDebugMsg("Line C")
            
            call GroupRemoveUnit(g, t)
            call BJDebugMsg("Line D")
            set t = FirstOfGroup(g)
            call BJDebugMsg("Line E")
            set id2 = GetUnitId(t)
            if t == null then
                call BJDebugMsg("t = null")
            endif
        endloop
        call ReleaseGroup(g)
        call BJDebugMsg("released the group")
        
        if check == true then
            call BJDebugMsg("check = true")
            if spot == 2 then
                set spot = 1
            endif
            set t = CreateUnit(p, 'H025', GetRectCenterX(Field[x][y]), GetRectCenterY(Field[x][y]),270. - (I2R(id)*180.))
            set Unit_Reg_Size[GetUnitId(t)] = 6
            set Unit_Reg_Size[id] = 6
            set Unit_Reg_Spot[GetUnitId(t)] = spot
            set Unit_Reg_Spot[id] = 2
            set Unit_Swimming[GetUnitId(t)] = true
            set Unit_X[GetUnitId(t)] = x
            set Unit_Y[GetUnitId(t)] = y
            set Unit_Steps[GetUnitId(t)] = GetHeroInt(t, true)
            call UnitLineUp(t)
        endif
        
    endif
    
    set u = null
    set t = null
    set p = null

    return false
endfunction

Here it gets past 'line A' but never displays other messages after that.









EDIT:
I just found a (what I thought was a minor) mistake and it fixed it.
I changed
JASS:
local integer spot
to
JASS:
local integer spot = 0
 
Status
Not open for further replies.
Top