HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Boolexprs?

01-20-2008, 01:56 PM#1
Gwypaas
How does boolexprs work? I know they are filters but im not 100% sure on how to use them. Can someone please show me a easy example on how to use boolexprs when you selects what units that's going to be damage by a spell?
01-20-2008, 02:28 PM#2
Jitse
A boolexpr, or boolean expression, is a function that returns a boolean (true or false). This can be used to set a certain condition with a trigger. Take a look at this:

Collapse JASS:
scope HeroDies

private function Conditions takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true
endfunction

private function Actions takes nothing returns nothing
    call BJDebugMsg("spam")
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( trig, Player(0), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

The function Conditions is a boolexpr. It returns true when it's a hero, and false when it isn't. That's how the triggering system knows when to trigger the Actions function.

The TriggerAddCondition adds the boolean expression to the trigger.
01-20-2008, 08:09 PM#3
vesuvan doppleganger
Boolexprs are also very useful for when you need to store a function. Wc3 doesn't have code arrays.
01-20-2008, 08:30 PM#4
Troll-Brain
Quote:
Originally Posted by vesuvan doppleganger
Boolexprs are also very useful for when you need to store a function. Wc3 doesn't have code arrays.
Hmm can you make an example plz i don't see how to use like an array code
01-25-2008, 01:26 PM#5
Troll-Brain
up.

Could someone explain me why boolxeprs are so usefull ?

EDIT : Oh well i see, just use a function which takes nothing and returns a boolean and use a boolxepr array
EDIT2 : Hmm not, i don't see how ..

Collapse JASS:
globals
boolexpr array Boolexpr
endglobals

function Test takes nothing returns boolean
// actions
return false
endfunction

function Init takes nothing returns nothing

set Boolexpr[1]=Condition(function Test)

endfunction

How can i use the function Test with the Boolexpr[1] ?
01-25-2008, 03:48 PM#7
chobibo
Collapse JASS:
local boolexpr be = Boolexpr[1]
01-25-2008, 03:55 PM#8
Troll-Brain
Quote:
Originally Posted by chobibo
Collapse JASS:
local boolexpr be = Boolexpr[1]
hmm i think you don't understand my question :p
How can i use the function Test like a call with the variable Boolexpr[1] ?
01-25-2008, 04:16 PM#9
chobibo
yeah I didn't mis-understood lol :p sorry, can you elaborate more
Edit: are talking about code arrays?
Collapse JASS:
function filter takes nothing returns boolean
     return true
endfunction

call GroupEnumUnitsInRange(g, x, y, radius, Boolexpr[1])
Like that?
01-25-2008, 04:36 PM#10
Troll-Brain
no, ok let's give a better explanation.

Collapse JASS:
globals
    boolexpr array Boolexpr
    integer I
endglobals

function A takes nothing returns boolean
    call BJDebugMsg("run")
    return false
endfunction

function Test takes nothing returns nothing
    local trigger t=CreateTrigger()
    local triggercondition trigC

    set Boolexpr[1]=Condition(function A) // should be done at the init of the map but it's just an example
    set trigC=TriggerAddCondition(t,Boolexpr[i])
    call TriggerEvaluate(t)
    call TriggerRemoveCondition(t,trigC)
    call DestroyTrigger(t)
    set t=null
    set trigC=null

endfunction

and the trigger Test :

Collapse JASS:
function Trig_Test_Actions takes nothing returns nothing
    set I=S2I(GetEventPlayerChatString())
    call Test()
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Test, Player(0), "", false )
    call TriggerAddAction( gg_trg_Test, function Trig_Test_Actions )
endfunction

so if i say "1" it must run the function A.
As you can see i've found the solution myself, but maybe there is a better way ...
01-25-2008, 04:41 PM#11
chobibo
Ok I get it, but I don't have any idea how lol! sorry
01-25-2008, 04:51 PM#12
HINDYhat
Quote:
Collapse JASS:
call TriggerRemoveCondition(t,trigC)
As far as I know, there's no need to remove triggerconditions. They remove themselves, so that's another cool part of exploiting boolexpr's.
01-25-2008, 04:54 PM#13
Troll-Brain
well, it would be great if we could use functions wich takes arguments ...
(I know that i can use globals instead).
thx for the tip