Conditions vs Actions

Expelliarmus

Where to change the sig?
Reaction score
48
1. Is it possible to have Actions in conditions and no action at all?
2. Is it possible to have Conditions in actions and no condition at all?
3. Is it generally faster than when separated?

JASS:
function Actions takes nothing returns nothing
    if some condition then
        // some Actions...
    endif
endfunction

//===========================================================================
function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(...)
    call TriggerAddAction( trig, function Actions )
endfunction


JASS:
function Condition takes nothing returns nothing
    if some condition then
        // some Actions...
    endif
    return false
endfunction

//===========================================================================
function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(...)
    call TriggerAddCondition( trig, Condition( function Condition ) )
endfunction


JASS:
function Condition takes nothing returns nothing
    return true
endfunction

function Actions takes nothing returns nothing
        // some Actions...
endfunction

//===========================================================================
function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(...)
    call TriggerAddCondition( trig, Condition( function Condition ) )
    call TriggerAddAction( trig, function Actions  )
endfunction


:)
 

Sooda

Diversity enchants
Reaction score
318
In trigger condition function you can't use waits. Conditions were bit slower than actions, I may be wrong here. Using conditions in some cases is better, for example when ability creates new triggers on fly, after it is simpler to clean up things. Cohadar (spelling?) Timer Tick system uses trigger conditions in very clever way, examine his work if it interests you.
 

Expelliarmus

Where to change the sig?
Reaction score
48
conclusion: trigger conditions are slower but easier to clean?
so like locations versus co-ordinates?
Cohadar (spelling?) Timer Tick system uses trigger conditions in very clever way, examine his work if it interests you.
So that was the code that had that! I was trying to find that, I saw it once, but I forgot like the next day. thanks

EDIT:
TT wasn't the one I was looking for... I remember there was one more, still by Cohadar.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
JASS:
 function Heal takes nothing returns boolean
    if GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.5 then
        call DestroyEffect(AddSpecialEffectTarget(EFFECT_HEAL, GetFilterUnit(), "overhead"))
        call SetUnitState(GetFilterUnit(), UNIT_STATE_LIFE, GetUnitState(GetFilterUnit(), UNIT_STATE_MAX_LIFE))
    endif
    return false
endfunction

call GroupEnumUnitsOfPlayer(g, Player(0), Condition(function Heal))


So, what does it do?
It heals all units of Player 1 (Red).

The "normal" way would be to test for units that are not dead, and return true is they aren't, or false if they are.
After that, you loop the group and heal them.

Instead of returning true though, this does all the actions in one go.
No second loop needed.

How that could be slower... no idea.

Additionally, since the group is never used for anything, it's enough to clear it before the enum, and you can also create it just once and keep it around.
 

Expelliarmus

Where to change the sig?
Reaction score
48
JASS:
function Heal takes nothing returns boolean
    if GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.5 then
        call DestroyEffect(AddSpecialEffectTarget(EFFECT_HEAL, GetFilterUnit(), "overhead"))
        call SetUnitState(GetFilterUnit(), UNIT_STATE_LIFE, GetUnitState(GetFilterUnit(), UNIT_STATE_MAX_LIFE))
    endif
    <b>return false</b>
endfunction

call GroupEnumUnitsOfPlayer(g, Player(0), Condition(function Heal))

Clever!!! What if bolded returns true instead?What will happen? Just curious ^_^

How that could be slower... no idea.
It seems too logical, no theory, no extensive benchmark needed.

Additionally, since the group is never used for anything, it's enough to clear it before the enum, and you can also create it just once and keep it around.
- it's enough to clear it before the enum
clear it or destroy it?

- you can also create it just once and keep it around.
keep it around?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> What will happen?

GroupEnum... collects units that got a "return true" in the provided group.
With false, the tested unit will not be put in the group.
Given this doesn't use the group, other than just the call, why store anything there?


Global variable:
group g = CreateGroup()


call GroupClear(g)
call GroupEnum...(g, ...

No need to destroy anything.
You're going to need it again anyway next time.
So, just keep it.
 

Expelliarmus

Where to change the sig?
Reaction score
48

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Conditions are better because they don't need to create a new thread and DestroyTrigger() works as it should with them. (There's a problem with DestroyTrigger() + Actions.)

The only cons is that you can't use waits, but when do you need that anyway? You can just use timers instead.
 

Expelliarmus

Where to change the sig?
Reaction score
48
threads? DestroyTrigger()?

- timers instead in conditions ??
JASS:
function Action takes nothing returns nothing
    if some condition then
        // some Actions...
    endif
endfunction

function Condition takes nothing returns nothing
    local timer clock = CreateTimer
    call TimerStart(clock, 5., false, function Actions) //?
    
    return false
endfunction

//===========================================================================
function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(...)
    call TriggerAddCondition( trig, Condition( function Condition ) )
endfunction
 

Viikuna

No Marlo no game.
Reaction score
265
JASS:
function Action takes nothing returns nothing
    if some condition then
        // some Actions...
    endif
endfunction

function Condition takes nothing returns nothing
    local timer clock = CreateTimer
    call TimerStart(clock, 5., false, function Actions) //?

     // it means that here is no wait, that return will happen just after 
    // that timer starts
    // if there would be wait, that return would happen after it.

    return false
endfunction

//===========================================================================
function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(...)
    call TriggerAddCondition( trig, Condition( function Condition ) )
endfunction


EDIT. With wait, that function Action is executed before return false. If you use timer return comes first.
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
Functions who return either true or false must return boolean values, not nothing or real or unit or any other of those.
JASS:
function Conditions takes nothing returns boolean
//Stuff goes here
return false
endfunction
 

Expelliarmus

Where to change the sig?
Reaction score
48
@viikuna.. err, ok...so the condition is false, but would the timer callback still run after 5 seconds?
@t.s.e : =P this was just an uncompiled example, i think the example brought my question without that confusion. nice pick up though!^_^
 

Flare

Stops copies me!
Reaction score
662
what's a thread? Is it like a function??
This should give you a better understanding of threads

The only particular thing I know (I'm not 100% sure) about threads is that each individual one has a separate op limit e.g. if you had to do 10,000 different things within a function (not likely :p), 1 function isn't going to be enough since you're gonna exceed the op limit, so you could split things into 2 (or more functions) that are doing 10000/numberOfFunctions things each, and use ExecuteFunc/vJASS equivalent (I forget whether it's .execute or .evaluate that starts a new thread) to run each 'block' of actions in separate threads
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
execute does, evaluate makes you able to write recursive functions.
 

Viikuna

No Marlo no game.
Reaction score
265
Yes timer callback is still executed, because it is another thread. That return false only ends that Condition function.
 
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