HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Better way to do it?

06-15-2004, 11:20 PM#1
Xinlitik
I've been messing around with filters using "and" and "or", trying to find out how I can get it to be cleaner. After an hour of compile errors I have given up...does anybody know a better way to do this?

Code:
function tsfilter1 takes nothing returns boolean
    return (IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) == true )
endfunction

function tsfilter2 takes nothing returns boolean
    return (IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function tsfilter0 takes nothing returns boolean
    return GetBooleanAnd(tsfilter1(),tsfilter2())
endfunction

[b]Condition(function tsfilter0)[/b]

That works...but it uses so many functions.. Isnt there a better way to do that?
06-16-2004, 04:41 AM#2
Narwanza
Quote:
Originally Posted by Xinlitik
I've been messing around with filters using "and" and "or", trying to find out how I can get it to be cleaner. After an hour of compile errors I have given up...does anybody know a better way to do this?

Code:
function tsfilter1 takes nothing returns boolean
    return (IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) == true )
endfunction

function tsfilter2 takes nothing returns boolean
    return (IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function tsfilter0 takes nothing returns boolean
    return GetBooleanAnd(tsfilter1(),tsfilter2())
endfunction

[b]Condition(function tsfilter0)[/b]

That works...but it uses so many functions.. Isnt there a better way to do that?

This is what I would do

Code:
function conditions takes nothing returns boolean
    return (IsUnitAliveBJ(GetFilterUnit()) and (IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())))
endfunction

Condition(function conditions)

FYI, == true means nothing, if you say
Code:
if udg_myBool then
it will only go on if myBool equates to true. If you want it to be when your boolean variable equates to false there are two ways that you could do it.

Way 1.
Code:
if udg_myBool == false then

Way 2.
Code:
if not udg_myBool then

GetBooleanAnd is also a useless function because there is an and keyword.

Code:
return udg_myBool1 [b]and[/b] udg_myBool2
06-16-2004, 04:51 AM#3
Xinlitik
Ahh thanks. I had tried and before and I could only get it to work in if/then functions lol. I must've been doing something wrong along the way.

Thanks a bunch. :D Rep given.
06-16-2004, 05:13 AM#4
Narwanza
Just a thing that I missed when I wrote that. Only use GetFilterUnit() when you are adding the function as a boolexpr on the trigger event. If you are calling it with the Filter(function condition) then you can use GetFilterUnit(), but if you are doing Condition(function condition) then you need to use event responses like GetTriggerUnit(), GetSpellAbilityUnit(), GetEnteringUnit(), etc. . . If you are doing something like TriggerRegisterRegionEvent(gg_trg_someTrig,udg_someRegion,Filter(function condition)) then use GetFilterUnit(), but if you are doing something like this

call TriggerRegisterRegionEventSimple?(gg_trg_someTrig,udg_someRect)
call TriggerAddCondition(gg_trg_someTrig,Condition(function condition))

then use event responses.