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

[JASS] Loop Inside Loop problem

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
NVM, solved it. But a question remains.

I was using a loop to pick units in small circles in a straigth line and adding all these units to a unit group. Then i have a loop to deal damage to units inside that group. The thing is, when the local real Damage variable had no value it was creating the groups constantly and all the specials effects (for testing purposes) every 0.5 to the facing of the caster, even when it wasn't casting anymore... It all worked out when I added a value to Damage... How's that the Damage Loop bugs the other loop that's before it if Damage = null?

JASS:
        loop // Through Small circles in a line to add these units to the SolarBeamDamageGroup
            exitwhen i > 15
            call BJDebugMsg("Index i: " + I2S(i))
            set OffsetX = CasterX + (i*75) * Cos(Facing * bj_DEGTORAD)
            set OffsetY = CasterY + (i*75) * Sin(Facing * bj_DEGTORAD)
            call AddSpecialEffect("Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl", OffsetX, OffsetY) // Just to test
            call GroupEnumUnitsInRange(g, OffsetX, OffsetY, 100, null)
            loop // Add the Enum units to the SolarBeamDamagedGroup
                set u = FirstOfGroup(g)
                exitwhen u == null
                if IsUnitEnemy(u, p) == true and IsUnitType(g, UNIT_TYPE_DEAD) == false then
                    call GroupAddUnit(udg_SolarBeamDamagedGroup, u)
                endif
                call GroupRemoveUnit(g, u)
            endloop 
            set i = i + 1
        endloop
        loop // Damage the Units in the SolarBeamGroup
            set u = FirstOfGroup(udg_SolarBeamDamagedGroup)
            exitwhen u == null
            call UnitDamageTarget(Caster, u, Damage, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            call GroupRemoveUnit(udg_SolarBeamDamagedGroup, u)
        endloop
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
But the Damage Loop has no relation with the Special Effect (in the Group Add loop)... I'm not sure if I understood: Are you saying that the game was stuck at the damage action because "Damage" was unset? Anyway, it's working now.

I have the call DestroyGroup(g) and null the unit and player later in the function, but I just wanted to focus on the loop thing...

I wonder: Is it ok? Is this part of the trigger fine? Can it be improved somehow? Is it MUI? Is it leakless? (I'll edit the first post to paste the whole trigger in a while)

I'm using the same loop (every 0.05) to charge damage, move dummies, handle the group to damage, etc. It's the first time I do something "complex" in JASS, and I just know about locals and removing most BJ's
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Like WaterKnight said, a function will halt if an unset variable is used. The following function will not diplay anything.
JASS:
function asdf takes nothing returns nothing
    local integer i
    set i = i + 1
    call BJDebugMsg("hello")
endfunction

In your func, you could calculate Cos(Facing * bj_DEGTORAD) into a variable and same for sin.
 
Status
Not open for further replies.
Top