• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Jass] Please explain to me, Units matching Condition

Status
Not open for further replies.
Level 14
Joined
Jul 1, 2008
Messages
1,314
Hello Guys,

Can you please explain to me, how to use the GUI-function
  • Set TempGroup = (Units in (Playable map area) matching (((Matching unit) is a Building) Equal to True))
I didnt find any hints, i searched in hives tutorials, but i still dont know how to use it in jass.

When i change this GUI-function in custom script, it shows multiple functions to handle the Mathing Condition, isn't there any wayt o code it easier?
JASS:
function Trig_trigg1_Func001002002 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == true )
endfunction

function Trig_trigg1_Actions takes nothing returns nothing
    set udg_TempGroup = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_trigg1_Func001002002))
endfunction

Would be very nice, if someone could help me :D

Greets
 
Level 7
Joined
Jul 20, 2008
Messages
377
Actually, I think that's pretty straightforward. When you try to build an unit group like that in JASS, you usually have to use multiple functions.

EDIT: That is, the function in where you actually invoke the unit group you're adding units to, and then another function to deal with what kind of a filter the units must match. So in short, calling function + filter function.

EDIT2: Also, clean your leaks. Use a local rect to store the playable map rect. Same for your filter function, store the filter unit.
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
y well thanks first of all!

@Leaks: LOL of course -.-! i only wanted an example....

@Topic: Well the thing is i just wondered, if i couldnt inline the second function likte this:

JASS:
function Trig_trigg1_Actions takes nothing returns nothing
    set udg_TempGroup = GetUnitsInRectMatching(GetPlayableMapRect(), IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == true)
endfunction

but then it always tells me, that there is an argument wrong, so i tried:
JASS:
function Trig_trigg1_Actions takes nothing returns nothing
    set udg_TempGroup = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == true))
endfunction

But this isnt correct too... i wonder why,as the only job, that the second function does, is, to return false or true.
So why cant i just inline the Conditions?

Greets
 
Level 7
Joined
Jul 20, 2008
Messages
377
Because the second parameter for GetUnitsInRectMatching() is a boolexpr. Now, the way you did it in the first inline example you gave - you are using a boolean expression, but this is not the same as a boolexpr. Now, in your second example, you used Condition(), which returns a conditionfunc, which extends boolexpr. However, the Condition() function takes as its argument a code. As you know, in JASS, when you see code as an argument, that means it must be a function.

Forgive me if I sound condescending or anything, I'm just trying my best to explain.

You can use an if function like this:

JASS:
if(GetUnitType(GetEnumUnit())='hfoo') then
call YourFunctionHere()
endif

Or whatever you want the condition to be.

Except that doesn't help. He needs a filter function for building an unit group. But I assume that by the fact you're using GetEnumUnit(), you're suggesting he uses something like that in his filter function... except that doesn't help very much. It is much more efficient to return a simple boolean expression.
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
Because the second parameter for GetUnitsInRectMatching() is a boolexpr. Now, the way you did it in the first inline example you gave - you are using a boolean expression, but this is not the same as a boolexpr. Now, in your second example, you used Condition(), which returns a conditionfunc, which extends boolexpr. However, the Condition() function takes as its argument a code. As you know, in JASS, when you see code as an argument, that means it must be a function.

Forgive me if I sound condescending or anything, I'm just trying my best to explain.



Except that doesn't help. He needs a filter function for building an unit group. But I assume that by the fact you're using GetEnumUnit(), you're suggesting he uses something like that in his filter function... except that doesn't help very much. It is much more efficient to return a simple boolean expression.

@Void:
I just wanted to write " sry dont know how to use your example concerning a "filter function" when i saw Sogas edit :).

@Soga: Thanks for your patience, im trying my best...

@All:
So it seems, i have to use 2 functions, as Soga explained, and it really makes sence, i cant use the function inlined, as it returns boolean instead of the argument code....

So there is no way to inline?

Greets
 
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
function Trig_trigg1_Actions takes nothing returns nothing
    set udg_TempGroup = GetUnitsInRectMatchingAll(GetPlayableMapRect())

    loop
          set unit = FirstOfGroup(udg_TempGroup)
          exitwhen unit == null
          call GroupRemoveUnit(unit,udg_TempGroup)
          if IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) then
                //your actions
          endif
    endloop
endfunction


this is what void said..
 
Level 7
Joined
Jul 20, 2008
Messages
377
Well, he said it wrong then.

But yes, Ciebron's example works. However, I think it's a bit unnecessary to make it inline. You end up making it do more work that way.
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
ooh ok guys, now i got it =D

@ciebron: thanks for explaining voids idea :)
@soga: tahnk you alot ;)

@Topic: well i use the filterfunctions now, as it seems to work fine :=)

+rep to you all by the way for helping :D

Greets
 
Status
Not open for further replies.
Top