• 🏆 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 Problem??

Status
Not open for further replies.
Level 5
Joined
Nov 14, 2007
Messages
161
im fairly new to JASS, but i needed to convert a non-MUI GUI code to MUI so ive been working on my JASS. I basically re-wrote it from scratch looking at my old code for some ideas trying to keep it leek free etc.
the skill basically creates cyclones around a point and has kinda a toilet bowl effect (soon to be finished) with a final big cyclone that grows in size at the end.

now my GUI version worked fine, just non-MUI and it's probably a 6 second long skill so there is a good chance for it to get messed up. anyway the beast is:

JASS:
function Trig_Tornado_JASS_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00Y' ) ) then
        return false
    endif
    return true
endfunction



function Trig_Tornado_JASS_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local location CasterPoint = GetUnitLoc(Caster)
    local location TargetPoint = GetSpellTargetLoc()
    local location TorSpawnPoint
    local unit DummyUnit
    local unit TempUnit
    local group enemies = CreateGroup() 
    local integer i = 4    
    local integer j = 0
    local integer k = 0

    
    loop
    set i = i - 1
    exitwhen i < 1
        call GroupEnumUnitsInRangeOfLoc(enemies, TargetPoint, 200.0, null)                                           
        
        loop
            set TempUnit = FirstOfGroup(enemies)                                                                         
            if IsUnitEnemy(TempUnit, GetOwningPlayer(Caster)) then                                                       
            call SetUnitLifeBJ (TempUnit, (GetUnitStateSwap(UNIT_STATE_LIFE, TempUnit) * 0.50 ) )                    
            endif
            call GroupRemoveUnit(enemies, TempUnit)
            exitwhen TempUnit == null
        endloop    
        
        loop
            exitwhen j > 24 
            set TorSpawnPoint = PolarProjectionBJ(TargetPoint, ( I2R(i) * 50.00 ), ( I2R(j) * 15.00 ))   
            call CreateUnitAtLoc (GetOwningPlayer(Caster), 'h00D', TorSpawnPoint, 270.0)
            set DummyUnit = GetLastCreatedUnit()                                                                     
            call UnitApplyTimedLife (DummyUnit, 'null', 1.00)                                                        
            call TriggerSleepAction( 0.00 )                                                                          
            set DummyUnit = null                                                                                     
            call RemoveLocation(TorSpawnPoint)                                                                       
            set j = j + 1
            call DisplayTimedTextToForce( GetPlayersAll(), 10.00, ( "i is : " + I2S(i) ) )
            call DisplayTimedTextToForce( GetPlayersAll(), 10.00, ( "j is : " + I2S(j) ) )
        endloop
        call DisplayTimedTextToForce( GetPlayersAll(), 10.00, ( "i2 is : " + I2S(i) ) )
    endloop
    
    call CreateUnitAtLoc (GetOwningPlayer(Caster), 'h00D', TorSpawnPoint, 270.0)
    set DummyUnit = GetLastCreatedUnit()
    call UnitApplyTimedLife (DummyUnit, 'null', 3.50)
    loop
        exitwhen k > 20
        call GroupEnumUnitsInRangeOfLoc(enemies, TargetPoint, ( I2R(i) * 05.00 ), null)                              
        if IsUnitEnemy(TempUnit, GetOwningPlayer(Caster)) then                                                       
            call SetUnitLifeBJ (TempUnit, (GetUnitStateSwap(UNIT_STATE_LIFE, TempUnit) * 0.95 ) )                    
        endif
        call SetUnitScalePercent( DummyUnit, ( I2R(k) * 15.00 ), ( I2R(k) * 15.00 ), ( I2R(k) * 10.00 ) )
        call TriggerSleepAction( 0.00 )
        call DisplayTimedTextToForce( GetPlayersAll(), 10.00, ( "k is : " + I2S(k) ) )
        set k = k + 1
    endloop    


    set CasterPoint = null     
    set TargetPoint = null  
    set TorSpawnPoint = null  
    call DestroyGroup(enemies)
    call RemoveLocation(CasterPoint)
    call RemoveLocation(TargetPoint)
    call RemoveLocation(TorSpawnPoint)
    set Caster = null

    set DummyUnit = null
    set TempUnit = null
endfunction

//===========================================================================
function InitTrig_Tornado_JASS takes nothing returns nothing
    set gg_trg_Tornado_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Tornado_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Tornado_JASS, Condition( function Trig_Tornado_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Tornado_JASS, function Trig_Tornado_JASS_Actions )
endfunction

ive been trying to de-bug it and it seems to loop one time, and loop the counter without re-looping the whole top section. anyone spot what's wrong with it?

another quick question, the
JASS:
call UnitApplyTimedLife (DummyUnit, 'null', 3.50)
i dont think i have correct, what is the 2nd param suppose to be?

(as ive said im new to jass so any help would be appreciated)

thanks ahead of time
YO_MA_MA

PS: ill be on tomorrow, hope to hear from ya then
 
Level 5
Joined
Nov 14, 2007
Messages
161
ok, thanks all for helping me on my 2nd question.
Does anyone know why my loops aren't working properly? Is it because the loop is in the loop? Usually that is fine, just wondering if it's a JASS thing and a function would be better or what.

Thanks again
YO_MA_MA
 
Level 5
Joined
Nov 14, 2007
Messages
161
Also, you're forgetting to reset the variables j and k every iteration of the i loop.
yeah i was explaining my problem to some friends during dinner, and all 3 of us though of the same exact thing at the same exact time. i felt dumb.

Your exitwhens are in rather bad places, which would cause a bit of weirdness.
where would be a good place than?

EDIT: ok so i worked on it some but now it gives the caster the timed life and not the dummys

JASS:
function Trig_Tornado_JASS_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local location CasterPoint = GetUnitLoc(Caster)
    local location TargetPoint = GetSpellTargetLoc()
    local location TorSpawnPoint
    local unit DummyUnit
    local unit TempUnit
    local group enemies = CreateGroup() 
    local integer i = 4    
    local integer j = 0

    
    loop
    set i = i - 1
    exitwhen i < 1
        call GroupEnumUnitsInRangeOfLoc(enemies, TargetPoint, 200.0, null)                                           
        
        loop
            set TempUnit = FirstOfGroup(enemies)                                                                         
            if IsUnitEnemy(TempUnit, GetOwningPlayer(Caster)) then                                                       
            call SetUnitLifeBJ (TempUnit, (GetUnitStateSwap(UNIT_STATE_LIFE, TempUnit) * 0.90 ) )                    
            endif
            call GroupRemoveUnit(enemies, TempUnit)
            exitwhen TempUnit == null
        endloop    
        
        loop
            exitwhen j > 24 

            set TorSpawnPoint = PolarProjectionBJ(TargetPoint, ( I2R(i) * 50.00 ), ( I2R(j) * 15.00 ))   
            call CreateUnitAtLoc (GetOwningPlayer(Caster), 'h00D', TorSpawnPoint, 270.0)
            set DummyUnit = GetLastCreatedUnit()                                                                     
            call UnitApplyTimedLife (DummyUnit, 'BTLF', 1.00)                                                        
            call TriggerSleepAction( 0.00 )                                                                          
            set DummyUnit = null                                                                                     
            call RemoveLocation(TorSpawnPoint)                                                                       
            set j = j + 1
        endloop
        call DisplayTimedTextToForce( GetPlayersAll(), 10.00, ( "i2 is : " + I2S(i) ) )
        set j = 0
    endloop
    
    set i = 0
    call CreateUnitAtLoc (GetOwningPlayer(Caster), 'h00D', TorSpawnPoint, 270.0)
    set DummyUnit = GetLastCreatedUnit()
    call UnitApplyTimedLife (DummyUnit, 'BTLF', 3.50)
    loop
        exitwhen i > 20
        call GroupEnumUnitsInRangeOfLoc(enemies, TargetPoint, ( I2R(i) * 05.00 ), null)                              
        if IsUnitEnemy(TempUnit, GetOwningPlayer(Caster)) then                                                       
            call SetUnitLifeBJ (TempUnit, (GetUnitStateSwap(UNIT_STATE_LIFE, TempUnit) * 0.75 ) )                    
        endif
        call SetUnitScalePercent( DummyUnit, ( I2R(i) * 15.00 ), ( I2R(i) * 15.00 ), ( I2R(i) * 10.00 ) )
        call TriggerSleepAction( 0.00 )
        call DisplayTimedTextToForce( GetPlayersAll(), 10.00, ( "i is : " + I2S(i) ) )
        set i = i + 1
    endloop    


    set CasterPoint = null     
    set TargetPoint = null  
    set TorSpawnPoint = null  
    call DestroyGroup(enemies)
    call RemoveLocation(CasterPoint)
    call RemoveLocation(TargetPoint)
    call RemoveLocation(TorSpawnPoint)
    set Caster = null
    set DummyUnit = null
    set TempUnit = null
endfunction
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
CreateUnitAtLoc doesn't save bj_lastCreatedUnit.

Here's a refactoring and fixing of your code:

JASS:
function Trig_Tornado_Jass_Filter takes nothing returns boolean
    if IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) then
        call SetWidgetLife(GetFilterUnit(), GetWidgetLife(GetFilterUnit())*.9 )
    endif
    return false
endfunction

function Trig_Tornado_JASS_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    //I removed CasterPoint since you didn't use it
    local location TargetPoint = GetSpellTargetLoc()
    local location TorSpawnPoint
    local unit DummyUnit
    local unit TempUnit
    local group enemies = CreateGroup()
    local integer i = 4
    local integer j = 0
    
    
    loop
        set i = i - 1
        exitwhen i < 1
        call GroupEnumUnitsInRangeOfLoc(enemies, TargetPoint, 200.0, Filter(function Trig_Tornado_Jass_Filter))

        loop
            exitwhen j > 24
            call UnitApplyTimedLife (CreateUnit(GetOwningPlayer(Caster),'h00D',GetLocationX(TargetPoint)+I2R(i)*50*Cos(I2R(j)*bj_PI/12),GetLocationY(TargetPoint)+I2R(i)*50*Sin(I2R(j)*bj_PI/12),270.), 'BTLF', 1.00)
            call TriggerSleepAction( 0. )
            set j = j + 1
        endloop
        call BJDebugMsg("i2 is : " + I2S(i))
        set j = 0
    endloop
    
    set i = 0
    //no idea what to do here... TorSpawnPoint isn't set by this point
    set DummyUnit = CreateUnitAtLoc (GetOwningPlayer(Caster), 'h00D', TorSpawnPoint, 270.)
    call UnitApplyTimedLife (DummyUnit, 'BTLF', 3.5)
    loop
        exitwhen i > 20
        call GroupEnumUnitsInRangeOfLoc(enemies, TargetPoint, ( I2R(i) * 05.00 ), null)
        if IsUnitEnemy(TempUnit, GetOwningPlayer(Caster)) then
            call SetWidgetLife (TempUnit, GetWidgetLife(TempUnit) * .75 )
        endif
        //note that units can't scale the axis separately
        call SetUnitScale( DummyUnit, ( I2R(i) * .15 ), ( I2R(i) * .15 ), ( I2R(i) * .15 ) )
        call TriggerSleepAction( 0. )
        call BJDebugMsg("i is : " + I2S(i))
        set i = i + 1
    endloop

    set TargetPoint = null
    call DestroyGroup(enemies)
    call RemoveLocation(TargetPoint)
    set Caster = null
    set DummyUnit = null
    set TempUnit = null
endfunction
 
Level 5
Joined
Nov 14, 2007
Messages
161
well i'd like to say thank you sofar but for the last effect of this skill, i was wanting to get a tornado to go off right in the middle. i got that part down, but i wanted it to grow during the last loop which it isnt. and grow i mean like 100% - like 300% or so as smooth as possible over about 2 seconds.

the code is the non-commented code so it skips right to it. ive tried 2 functions in numerous ways but it just isnt growing how i want. a possible idea would be just an effect growing, cus the unit im using is just a dummy unit model. if this seems like it would work, could you help me out with it? any other ideas would be good too.

JASS:
function Trig_Tornado_JASS_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local location TargetPoint = GetSpellTargetLoc()
    local location TorSpawnPoint    
    local unit DummySetWidgetLifeUnit
    local unit DummyUnit    
    local unit TempUnit    
    local group enemies = CreateGroup()    
    local integer i = 3    
    local integer j = 0    
    
//    loop            
//        exitwhen i < 1        
//        call GroupEnumUnitsInRangeOfLoc(enemies, TargetPoint, 200.0, Filter(function Trig_Tornado_Jass_Filter))        
//        loop            
//            exitwhen j > 24            
//            call UnitApplyTimedLife (CreateUnit(GetOwningPlayer(Caster),'h00D',GetLocationX(TargetPoint)+I2R(i)*50*Cos(I2R(j)*bj_PI/12),GetLocationY(TargetPoint)+I2R(i)*50*Sin(I2R(j)*bj_PI/12),270.), 'BTLF', 1.00)            
//            call TriggerSleepAction( 0. )            
//            set j = j + 1        
//        endloop        
//        call BJDebugMsg("i2 is : " + I2S(i))        
//        set i = i - 1
//        set j = 0    
//    endloop
//

     
    set i = 1    
    set DummyUnit = CreateUnitAtLoc (GetOwningPlayer(Caster), 'h00D', TargetPoint, 270.)    
    call UnitApplyTimedLife (DummyUnit, 'BTLF', 6.5)    
    loop        
        exitwhen i > 10        
        call GroupEnumUnitsInRangeOfLoc(enemies, TargetPoint, ( I2R(i) * 05.00 ), null)        
        if IsUnitEnemy(TempUnit, GetOwningPlayer(Caster)) then            
            call SetWidgetLife (TempUnit, GetWidgetLife(TempUnit) * .75 )        
        endif        
        //call SetUnitScale (DummyUnit, (I2R(i) * 2), (I2R(i) * 2), (I2R(i) * 2))
        call SetUnitScalePercent( DummyUnit, ( I2R(i) * 15 ), ( I2R(i) * 15 ), ( I2R(i) * 15 ) )        
        call TriggerSleepAction( 0.5 )           
        set i = i + 1    
    endloop
    
        
    set TargetPoint = null    
    call DestroyGroup(enemies)    
    call RemoveLocation(TargetPoint)    
    set Caster = null    
    set DummyUnit = null    
    set TempUnit = null
endfunction

Thanks
YO_MA_MA
 
Level 5
Joined
Nov 14, 2007
Messages
161
well as of right now, it isnt going at all. i've read timers work better just like you say, but im not quite sure how to do one in JASS and i rarely work with them in GUI so i lack timer knowledge.
 
Level 5
Joined
Nov 14, 2007
Messages
161
BLA, just finished my first week of my 3rd year of college, but what the hell i can learn more >.>


is there something that im missing that isnt letting the current code work now?

i want it to create the unit, assign it to dummy, then make it grow in size and disappear (with timed life). it seems so easy yet it's not working.
 
Level 5
Joined
Nov 14, 2007
Messages
161
gosh dang it!

tempunit, dummyunit their all the same damn unit >.< (thanks though lol)

testing..

EDIT: meh looks a little jerky in some spots, but for now i think ill live with it. i changed up a few things so it damages how i want.

thanks alot PurplePoot!
 
Last edited:
Status
Not open for further replies.
Top