• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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,240
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