What's wrong with this code?

Sim

Forum Administrator
Staff member
Reaction score
534
Hi!

I've got a problem with a code... It's been like 3 days I'm finding to find a way around it but I just can't... it must be MUI!

Here it is...

Code:
function Trig_Attack_Yellow_Copy_Func003002002 takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) != 'e00E' )
endfunction

function Trig_Attack_Yellow_Copy_Actions takes nothing returns nothing
    local integer i = GetConvertedPlayerId(GetOwningPlayer(GetEnteringUnit()))
    local integer ivar
    local group Units_of_Player
    local unit u
    local location sy
    local location p
    set Units_of_Player = GetUnitsOfPlayerMatching(GetOwningPlayer(GetEnteringUnit()), Condition(function Trig_Attack_Yellow_Copy_Func003002002))
    set p = GetRectCenter(udg_AttackerSpawn[i])
    call SetUnitPositionLoc( GetEnteringUnit(), p )
    set ivar = 1
    loop
        exitwhen ivar > CountUnitsInGroup(Units_of_Player)
        call TriggerSleepAction( 0.02 )
        set u = GroupPickRandomUnit(Units_of_Player)
        set sy = GetRandomLocInRect(gg_rct_Spawn_Yellow)
        call IssuePointOrderLocBJ( u, "attack", sy )
        call GroupRemoveUnitSimple( u, Units_of_Player )
        call RemoveLocation(sy)
        set ivar = ivar + 1
    endloop
    call RemoveLocation(p)
    call DestroyGroup(Units_of_Player)
endfunction

//===========================================================================
function InitTrig_Attack_Yellow takes nothing returns nothing
    set gg_trg_Attack_Yellow = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Attack_Yellow, gg_rct_Attack_Yellow )
    call TriggerAddAction( gg_trg_Attack_Yellow, function Trig_Attack_Yellow_Copy_Actions )
endfunction

What it does ? it is a mass attack command. When your wisp enter ''Attack Yellow'' region, all your units attack Yellow. Really, this code works in GUI. It worked well with Integer A. But since Integer A was used everytime a player wanted to mass attack another one, it bugged, there was only one solution : make it MUI.

There is a huge background history to this trigger : First I used Unit Groups. I got insane Unit Congestion. Next I deleted it from the map and when Darthfett told me with Integer Loops and waits the units stopped Congestion, I tried again. It worked !

But only with Integer A. I tried with a global integer variable and it didn't work either. So I decided to switch to JASS and use a local integer variable.

It doesn't work either.

What is the problem exactly ? It doesn't move all the units! With Integer A all the units are moved ! As soon as I use an integer variable, global or not, half of the units are moved. I think the problem is somewhere close to this line :

exitwhen ivar > CountUnitsInGroup(Units_of_Player)

But I can't be sure :(

Any ideas why it doesn't send all the units?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> exitwhen ivar > CountUnitsInGroup(Units_of_Player)
> call GroupRemoveUnitSimple( u, Units_of_Player )

Well, there's less and less units, while ivar just grows...

loop
- set pickedunit = FirstOfGroup(groupvariable)
- exitwhen pickedunit == null
- call GroupRemoveUnit(groupvariable, pickedunit)
- // do something with pickedunit
- ...
endloop
 

Sim

Forum Administrator
Staff member
Reaction score
534
Ya it worked. Thus, without unit congestion. They prolly go at the same time, though it forms a huge line, instead of a mass. But that's 1000000 times better than unit congestionning.

Thanks alot :)
 

SFilip

Gone but not forgotten
Reaction score
634
just though you should know...that trigger leaks.
all locals except for integer, boolean, real and string must be set to null on the end of the trigger.
Code:
    set Units_of_Player = null
    set u = null
    set sy = null
    set p = null
 

Sim

Forum Administrator
Staff member
Reaction score
534
Before the removings or after?
 

Sim

Forum Administrator
Staff member
Reaction score
534
Ok good.

I'm impatient to learn JASS more. ;)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top