HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

loops

08-01-2009, 02:46 PM#1
Tot
could it be,that vJASS (?and JASS?) have problemes with loops in loops?

if I run a loop in a loop (same function, etc) the inner loop's not used

Collapse JASS:
function blabla takes blabla returns blabla
loop
blabla
loop
laberlaber
endloop
endloop
endfunction

the laberlaber part is not used
08-01-2009, 03:22 PM#2
Fledermaus
Collapse JASS:
local integer i = 0 
local integer j = 0
loop
  exitwhen i == 5
    set j = 0
    loop
      exitwhen j == 3
        call DoSomething()
        set j = j +1
    endloop
    call DoSomethingElse()
    set i = i +1
endloop


?
08-01-2009, 03:35 PM#3
Tot
Collapse JASS:
private function Affect takes group g, integer level returns nothing
        local group a=g
        local group temp
        
        local unit u1
        local unit u2
    

        loop
            set u1 = FirstOfGroup(a)
            exitwhen u1 == null
            call GroupRemoveUnit(a, u1)
            call GroupEnumUnitsInRange(temp, GetUnitX(u1),GetUnitY(u2),Area(level),Condition(function Targets))
            loop
                set u2 = FirstOfGroup(temp)
                exitwhen u2 == null
                call GroupRemoveUnit(temp, u2)
                call AffectUnit(u2, u1, level)
            endloop
        endloop
    endfunction

call AffectUnit(u2, u1, level) is not triggered
i've checked all values and they are >0 or true
08-01-2009, 03:41 PM#4
Hans_Maulwurf
Quote:
Originally Posted by Tot
Collapse JASS:
private function Affect takes group g, integer level returns nothing
        local group a=g
        local group temp
        
        local unit u1
        local unit u2
    

        loop
            set u1 = FirstOfGroup(a)
            exitwhen u1 == null
            call GroupRemoveUnit(a, u1)
            call GroupEnumUnitsInRange(temp, GetUnitX(u1),GetUnitY(u2),Area(level),Condition(function Targets))
            loop
                set u2 = FirstOfGroup(temp)
                exitwhen u2 == null
                call GroupRemoveUnit(temp, u2)
                call AffectUnit(u2, u1, level)
            endloop
        endloop
    endfunction

call AffectUnit(u2, u1, level) is not triggered
i've checked all values and they are >0 or true

you got a typo. the y coordinate is false (0), so the groupenum will fail
08-01-2009, 03:44 PM#5
Tot
Quote:
Originally Posted by Hans_Maulwurf
you got a typo. the y coordinate is false (0), so the groupenum will fail

correncted and still nothing works
08-01-2009, 03:51 PM#6
Hans_Maulwurf
You don't create the group "temp", so the groupenum will fail
08-01-2009, 04:02 PM#7
Tot
now it looks like this

Collapse JASS:
    private function Affect takes group g, integer level returns nothing
        local group a=g
        local group temp
        
        local unit u1
        local unit u2
        
        set a= CreateGroup() 
        set temp=CreateGroup()    
        loop
            set u1 = FirstOfGroup(a)
            exitwhen u1 == null
            call GroupRemoveUnit(a, u1)
            call GroupEnumUnitsInRange(temp, GetUnitX(u1),GetUnitY(u1),Area(level),Condition(function Targets))
            loop
                set u2 = FirstOfGroup(temp)
                exitwhen u2 == null
                call GroupRemoveUnit(temp, u2)
                call AffectUnit(u2, u1, level)
            endloop
        endloop
    endfunction

and still nothing works
08-01-2009, 04:11 PM#8
Hans_Maulwurf
Now you use a new empty group "a" which doesnt contain the units of group "g"…

Collapse JASS:
    private function Affect takes group g, integer level returns nothing
        local group a = CopyGroup(g)
        local group temp = CreateGroup() 
        
        local unit u1
        local unit u2
        
        loop
            set u1 = FirstOfGroup(a)
            exitwhen u1 == null
            call GroupRemoveUnit(a, u1)
            call GroupEnumUnitsInRange(temp, GetUnitX(u1),GetUnitY(u1),Area(level),Condition(function Targets))
            loop
                set u2 = FirstOfGroup(temp)
                exitwhen u2 == null
                call GroupRemoveUnit(temp, u2)
                call AffectUnit(u2, u1, level)
            endloop
        endloop
    endfunction

Expand CopyGroup:

also don't forget to destroy the groups, or even better use grouputils
08-01-2009, 04:25 PM#9
Tot
still doesn't work
08-01-2009, 05:06 PM#10
Pyrogasm
Then it's probably something with your Targets filter func.
08-01-2009, 05:10 PM#11
Tot
targets filter checks only if units hp>0.4...
08-01-2009, 05:22 PM#12
Pyrogasm
Can you post everything you have for the function and the filter? I bet there's some stupid error you made like using GetEnumUnit() instead of GetFilterUnit()
08-01-2009, 05:31 PM#13
Tot
code

have changed targets to what is was before (still dont work)
Collapse nearly complete code:
scope DemonicOrbs2

    // Settings
    
    globals
        private player Owner
        
        private constant string EFFECT = "Abilities\\Weapons\\Bolt\\BoltImpact.mdl"
        private constant string EFFECT_ATTACH = "overhead"
        
        private constant real MOVE_PERIOD = 0.025       //time in seconds projectiles are moved
                
        //Superformula
        private constant real FORMULA_m =5
        private constant real FORMULA_n1=2
        private constant real FORMULA_n2=7
        private constant real FORMULA_n3=7
        private constant real NUMBEROFDUMMIES=40
        //Superformula
        
        private constant integer SPELL_ID = 'A000'
        private constant integer PROJECTILE = 'e003'
        private constant integer PROJECTILE_ABILITY_ID = 'A001'
        
        private constant boolean ORIGINAL = false
    endglobals
    
    private constant function Range takes integer level returns real
        return 300.0 //the radius of the circle
    endfunction
    
    private constant function Speed takes integer level returns real
        return 0.1 //the speed of the projectiles
    endfunction
    
    private constant function Duration takes integer level returns real
        return 10.0 //the number of rotations
    endfunction
    
    private constant function Area takes integer level returns real
        return 75.0 //Area around every dummy in which all enemies will take damage
    endfunction
    
    private constant function Damage takes integer level returns real
        return 50.0+level*50.0 //damage dealt
    endfunction
        
    private function Targets takes nothing returns boolean
        return IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING)==false and GetWidgetLife(GetFilterUnit())>0.405 and IsUnitEnemy(GetFilterUnit(), Owner)
    endfunction
                  
// !!D!!O!! !!N!!O!!T!! !!C!!H!!A!!N!!G!!E!! !!F!!O!!L!!L!!O!!W!!I!!N!!G!!
    
    private function AffectUnit takes unit affected, unit projectile, integer level returns nothing
        call UnitDamageTarget(projectile, affected, Damage(level)*MOVE_PERIOD, false, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL , WEAPON_TYPE_WHOKNOWS)
        call DestroyEffect(AddSpecialEffectTarget(EFFECT, affected, EFFECT_ATTACH))
    endfunction
                            
    private keyword Superformula
    
    globals
        private TFormula array list
  
        private integer listmax = 0
   endglobals

    private function Move takes nothing returns nothing
        local integer i=0
        loop
            exitwhen i>=listmax
            call list[i].rotateInLine()
            call list[i].increaseLivingTime(MOVE_PERIOD)

call DisplayTextToForce(GetPlayersAll(),R2S(list[i].getLivingTime()))
call DisplayTextToForce(GetPlayersAll(),I2S(i))
            if list[i].isDestroyed==true then
                set listmax=listmax-1
                set list[listmax].placeinlist = list[i].placeinlist
                set list[list[i].placeinlist]=list[listmax]
            endif
            set i = i + 1
        endloop
    endfunction
    
    private function SpellCastCondition takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction

    private function SpellCast takes nothing returns nothing
        local unit u = GetTriggerUnit()
        
        local location l=GetSpellTargetLoc()
        
        local real angle= Atan2(GetLocationY(l) - GetUnitY(u), GetLocationX(l) - GetUnitX(u))
        
        local integer level=GetUnitAbilityLevel(u, SPELL_ID)
        set list[listmax]=TFormula.createTFormula(u,GetUnitLoc(u), Range(level), Speed(level), Duration(level), NUMBEROFDUMMIES, FORMULA_m, FORMULA_n1, FORMULA_n2, FORMULA_n3, PROJECTILE, level, ORIGINAL)
        set list[listmax].placeinlist=listmax
        set listmax=listmax+1
        call RemoveLocation(l)
        set l = null
        set u = null
    endfunction

//===========================================================================
    function InitTrig_DemonicOrbs2 takes nothing returns nothing
        local timer t = CreateTimer()
    
        set gg_trg_DemonicOrbs2 = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_DemonicOrbs2, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( gg_trg_DemonicOrbs2, Condition( function SpellCastCondition ) )
        call TriggerAddAction( gg_trg_DemonicOrbs2, function SpellCast )
                
        call TimerStart(t, MOVE_PERIOD, true, function Move)
    endfunction

endscope

and a new problem occured he's mixing up the lists

eg.
list[0].t=10
list[1].t=10

in game t=20

much fun guys
08-02-2009, 12:15 AM#14
Anitarf
Quote:
Originally Posted by Tot
If you're still using the code you linked to, then Hans_Maulwurf already pointed out what your problem is, re-read his post.
08-02-2009, 12:15 PM#15
Tot
sry pointed to wrong thread

now it's the right one