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

[vJASS] problem with if in loop

Status
Not open for further replies.
Level 23
Joined
Apr 16, 2012
Messages
4,041
well, i have this inside of my trigger(this trigger is hella longer but this is what doesnt work)
JASS:
    local unit first
    local unit ustun
    local group g = CreateGroup()
    local integer stuncount = 10
    local integer stunlevel = whatever
    if something then 
        call GroupEnumUnitsInRange(g, ux, uy, someradius, null)
        call BJDebugMsg("enumed")
        loop
            set first = FirstOfGroup(g)
            exitwhen first == null or stuncount == 0
            call GroupRemoveUnit(g, first)
            call BJDebugMsg("next to loop")
            if not IsUnitAlly(first, GetOwningPlayer(ustun)) then // if IsUnitEnemy(first, GetOwningPlayer(ustun) then also didnt work
                call BJDebugMsg("inside of loop")
                set ustun = CreateUnit(GetOwningPlayer(u), 'hRsu', ux, uy, 0)
                call UnitAddAbility(ustun, myability)
                call SetUnitAbilityLevel(ustun, myability, stunlevel)
                call UnitApplyTimedLife(ustun, 'BTLF', 0.75)
                call IssueTargetOrder(ustun, "thunderbolt", first) //also tried call IssueTargetOrderById(ustun, 852095, first) and didnt work
                call BJDebugMsg("loop finished")
                set ustun = null
            endif
            set stuncount = stuncount - 1
        endloop
    endif

it goes all the way to next to loop but it never fires loop finished even though it should fire it 10 times at this example.
The locals are set differently and also myability is something else but I dont want to spoil it.

So from the Debug messages it looks like the if breaks this piece of code.
The ability has 0 mana cost, 0 cooldown and the dummy unit has has maximum possible mana, I double checked that.

Anyone any help?
edit: found out that the inside the loop also doesnt fire, any way to fix the if because what else can be wrong there, there is nothing between debugmsg and if :D and only things inside the loop doesnt fire
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
It's not a matter if it's inside a if or not.
In jass using an unitialized variable crash the thread.

You don't have to give an initial value (local yourVariable = someValue), just make sure your variable has some value when you use it.

Anyway there is failed logic in your code.

if not IsUnitAlly(first, GetOwningPlayer(ustun)) while ustun refers to no unit.
 
Status
Not open for further replies.
Top