• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[JASS] ForGroup

Status
Not open for further replies.
Level 8
Joined
Nov 9, 2008
Messages
502
Hi.

So I need to get the unit in group g whose fly height is closest to the fly height of a unit.

I'm getting confused because ForGroup needs to call a function which would require to use a global. Is it possible I can use ForGroup in an If statement to return a unit? How would I do this?

Also, am I right in thinking GroupEnumUnitsInRange doesn't take Z into account and if it doesn't, can I use AND in a boolexp's return? Like so....

JASS:
function myFilter takes nothing returns boolean
     return GetOwningPlayer(GetFilterUnit()) == Player(15) and GetUnitFlyHeight(GetFilterUnit()) == GetUnitFlyHeight(udg_u[i])
endfunction

but it says a boolexp should take nothing so I can't put a value from another trigger (i) into it. How to work around???


Most important question is whether GroupEnumUnitsInRange takes Z into account.....
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
If the function from where you call ForGroup or GroupEnumUnitsInRange is the "action" function (meaning event responses work there), then you can use event responses (if your unit is stored there). If not, then using globals is the only way, though I don't see a problem in that, because it all happens in an instant.

An example:

JASS:
function Callback takes nothing returns nothing
    local unit u = GetTriggerUnit()
endfunction

function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local group g = ...
    // ...
    call ForGroup(g, function Callback)
endfunction

Same thing is possible with boolexprs.

Also, you have to check for the flying height in a boolexpr or in a callback, there's no other way (there is no GroupEnum function that checks for flying height). I didn't quite get what you asked there, though.
 
Level 8
Joined
Nov 9, 2008
Messages
502
So can I do AND in a boolexpr?

And I saw in a tutorial that a basic boolexpr goes like

JASS:
function LessThan20ManaCallback takes nothing returns boolean
     // Get the next unit to examine
     local unit nextUnit = GetFilterUnit()
     // Check to see if it satisfies our condition
     return GetUnitState(nextUnit, UNIT_STATE_MANA) < 20
endfunction

but that unit leaks a handle which I can't null in the same trigger because trigger won't play anything after return right? What gives?

An example:

JASS:
function Callback takes nothing returns nothing
    local unit u = GetTriggerUnit()
endfunction

function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local group g = ...
    // ...
    call ForGroup(g, function Callback)
endfunction
OK so I can pass triggering unit and other event registers to functions called within an actions function? Didn't think you can get triggering unit from a seperate function. Unfortunately that doesn't help in my situation but thanks xD

EDIT


God Damn jass is frustrating. I misunderstood GroupEnumUnitsInRange. I must use another function to return a group bloody hell.
 
Last edited:
Level 14
Joined
Nov 18, 2007
Messages
816
JASS:
function Callback takes nothing returns nothing
    local unit u = GetTriggerUnit()
endfunction

Actually, its
JASS:
function Callback takes nothing returns nothing
    local unit u = GetEnumUnit()
endfunction

JASS:
function LessThan20ManaCallback takes nothing returns boolean
     // Get the next unit to examine
     local unit nextUnit = GetFilterUnit()
     // Check to see if it satisfies our condition
     return GetUnitState(nextUnit, UNIT_STATE_MANA) < 20
endfunction

Yes, that function leaks, heres how to avoid:
JASS:
function LessThan20ManaCallback takes nothing returns boolean
     // Get the next unit to examine
     local unit nextUnit = GetFilterUnit()
     local boolean b = GetUnitState(nextUnit, UNIT_STATE_MANA) < 20
     // Check to see if it satisfies our condition
     set nextUnit=null
     return b
endfunction
 
Status
Not open for further replies.
Top