Creating Groups and Force variable and seting them up?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
If I Create groups or force, in the globals tag, is it best to create them when they are needed like below, adding another variable for counting them, Or...

JASS:
globals
    group indexGroup_u
    unit temp_uForIndex
    integer indexMax_u
    integer indexMaxRecord_u
    unit array index_u
    group array index_u_Group
endglobals

function IndexUnit takes nothing returns nothing

    if indexMax_u == indexMaxRecord_u then  // Creates the Group if a new top is reached. 
      set indexMaxRecord_u = indexMaxRecord_u + 1
      set indexGroup_u[indexMaxRecord_u] = CreateGroup()
    endif
    
    set index_u[indexMax_u] = temp_uForIndex
    call SetUnitUserData(index_u[indexMax_u], indexMax_u)
    call GroupAddUnit(index_u[indexMax_u], indexGroup_u)
    set indexMax_u = indexMax_u + 1
endfunction

function DeindexUnit takes nothing returns nothing
endfunction

... Just looping through them all as seen here, this not a group created counter. Also, can I loop through this entire series?

JASS:
function InitTrig_Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    
    //Setup Variables
    
    loop
        exitwhen i > JASS_MAX_ARRAY_SIZE
            set index_u_Group[i] = CreateGroup()
            set indexGroup_u[i] = CreateGroup()
            set i = i + 1
    endloop
  set t = null
    
endfunction

Perhaps groups and force (and what else there is) is best created using the variable creating menu making them "udg_VARIABLE" and avoiding the problem with creating them? Or do you have to set them up aswell?

How do you do it?
 

oh! So I need no counter! thanks ;)

Changed it to this, don't know how to inline that event though.

JASS:
globals
    group uIndexGroup = CreateGroup()
    integer uIndexMax = -1
    unit temp_uToIndex
    unit array uIndexUnit 
    group array uIndexLocalGroup
endglobals

function IndexUnit takes nothing returns nothing
    set uIndexMax = uIndexMax + 1
    set uIndexUnit[uIndexMax] = temp_uToIndex
    call SetUnitUserData(uIndexUnit[uIndexMax], uIndexMax)
    
    if uIndexLocalGroup[uIndexMax] == null then
        set uIndexLocalGroup[uIndexMax] = CreateGroup()
    endif
endfunction

function DeindexUnit takes unit u returns nothing
    local group tempGroup = CreateGroup()
    
    set uIndexUnit[GetUnitUserData(u)] = uIndexUnit[uIndexMax]
    call SetUnitUserData(uIndexUnit[GetUnitUserData(u)], GetUnitUserData(u) )
    call GroupRemoveUnit(uIndexGroup, uIndexUnit[uIndexMax])
    
    if CountUnitsInGroup(uIndexLocalGroup[uIndexMax]) > 0 then
        set tempGroup = uIndexLocalGroup[GetUnitUserData(u)] 
        set uIndexLocalGroup[GetUnitUserData(u)] = uIndexLocalGroup[uIndexMax]
        set uIndexLocalGroup[uIndexMax] = tempGroup
    endif
   
endfunction

function IndexedUnitDies takes nothing returns nothing
  if IsUnitInGroup(GetTriggerUnit(), uIndexGroup) == true then
    call DeindexUnit(GetTriggerUnit())
  endif
endfunction

function InitTrig_UnitIndex takes nothing returns nothing
  local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction(t, function IndexedUnitDies) 
  set t = null
endfunction
 
Last edited:
Last thing, this line then:
JASS:
    if CountUnitsInGroup(uIndecLocalGroup[uIndexMax] > 0 then
      call GroupAddGroup(uIndexLocalGroup[uIndexMax], uIndexLocalGroup[uIndexMax]
    endif

best would be if I could switch places between the uIndexLocalGroup[GetUnitUserData(u)] and uIndexLocalGroup[uIndexMax]

Perhaps if I create a local group, give the deindex unit group to it, set the last group to the first and then set the last group to the temp group

like this:
  • Actions
    • Set temp_g = g1
    • Set g1 = g2
    • Set g2 = temp_g
or perhaps I should just replace the dying unit and att that unit to its place.. ;p
 
Status
Not open for further replies.
Back
Top