How to run a unit through a filter without the filter taking anything

saw792

Is known to say things. That is all.
Reaction score
280
It also leaks two groups. But if I must fix my freehanded code...
JASS:
function GroupRunFilter takes group g, boolexpr filter returns group
  local group g1 = CreateGroup()
  local group g2 = CreateGroup()
  local integer i = 0
  local unit u = null
  call GroupEnumUnitsInRect(g1, bj_mapInitialPlayableArea, filter)
  call GroupAddGroup(g, g2)
  loop
    set u = FirstOfGroup(g2)
    exitwhen u == null
    if IsUnitInGroup(u, g1) == false then
      call GroupRemoveUnit(g)
    endif
    call GroupRemoveUnit(u, g2)
  endloop
  call DestroyGroup(g1)
  call DestroyGroup(g2)
  set g1 = null
  set g2 = null
  return g
endfunction
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Does JASS pass by into functions a copy of the original, or a reference to the original? I guess what I'm asking is, doesn't that modify the original group that was passed in? My guess is no because there'd be no need to return it otherwise.
 

saw792

Is known to say things. That is all.
Reaction score
280
Yes, my function does modify the group you pass it. That's the entire point of the function. It removes all units from it that don't match the filter. Jass handles are pointers to the actual object (or to the object's integer ID), and thus when you pass an argument to a function you pass the reference to the object, the object doesn't get copied.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
He wants to add units into a new group that meet a certain condition. Thats why my function was so weird. Perhaps he just doesn't know what he wants xD
 

saw792

Is known to say things. That is all.
Reaction score
280
Oops, read it the other way around. Quick change, probably can be optimised to use less groups but meh...
JASS:
function GroupRunFilter takes group g, boolexpr filter returns group
  local group g1 = CreateGroup()
  local group g2 = CreateGroup()
  local group g3 = CreateGroup()
  local integer i = 0
  local unit u = null
  call GroupEnumUnitsInRect(g1, bj_mapInitialPlayableArea, filter)
  call GroupAddGroup(g, g2)
  call GroupAddGroup(g, g3)
  loop
    set u = FirstOfGroup(g2)
    exitwhen u == null
    if IsUnitInGroup(u, g1) == false then
      call GroupRemoveUnit(g3)
    endif
    call GroupRemoveUnit(u, g2)
  endloop
  call DestroyGroup(g1)
  call DestroyGroup(g2)
  set g1 = null
  set g2 = null
  return g3
endfunction
 

cleeezzz

The Undead Ranger.
Reaction score
268
>Perhaps he just doesn't know what he wants xD

lol i do know what i want, it just seems like theres no direct way to make a custom function to run a filter, i didn't think it would be so complicated, (saw, i appreciate the code but i guess it takes away from the simplicity and efficient factor i was looking for)

+rep to all (if possible), ill stick with the loops.
 

cleeezzz

The Undead Ranger.
Reaction score
268
uh huh. and how do i filter units like that using a custom function? please read the entire thread first
 
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