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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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