HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Conditions vs If/Then/Else: which is better?

04-18-2009, 09:16 PM#1
Michael Peppers
I'm going to explain this: in my few experiences with JASS I'm not using conditions to make actions work, I call them with If/Then/Else statements, example:

Collapse JASS:
function blabla_Actions takes nothing returns nothing
if (GetSpellAbilityId() == 'A000') then
    //Actions here
else
    call DoNothing () //Obviously, not necessary to call nothing, but I'm doing it anyway :P
endif
endfunction

function InitTrig_blabla takes nothing returns nothing
    set gg_trg_blabla = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_blabla, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(gg_trg_blabla, function blabla_Actions)
endfunction
Opinions on this way of coding? Can it cause problems? Is it faster, slower than Conditions or it doesn't change a thing because Conditions == If statements?

May seem a silly question, but I'd like to have a clarification.

And don't point out that I omitted the "event" part :P

EDIT: Added the event part :P
04-18-2009, 10:02 PM#2
akolyt0r
AFAIK its slower (since Actions are slower than Conditions, but Actions can use TriggerSleepAction and Conditions cant...)
When you dont have any waits in your code, you can write your whole spell in the Condition however (just don add a triggeraction...), that should be slightly faster ...
04-18-2009, 10:13 PM#3
Michael Peppers
Quote:
Originally Posted by akolyt0r
AFAIK its slower (since Actions are slower than Conditions, but Actions can use TriggerSleepAction and Conditions cant...)
When you dont have any waits in your code, you can write your whole spell in the Condition however (just don add a triggeraction...), that should be slightly faster ...
Using only Conditions? I'll give it a try ASAP...

So, "If/Then/Else" is slower compared to "Conditions", because of its existance in "Actions", that is slower than "Conditions".

But then I have another question: Is a "Conditions + Actions" trigger faster than a trigger like mine (without Conditions)?
04-18-2009, 10:30 PM#4
Vexorian
Quote:
But is "Conditions + Actions" faster than only "If/Then/Else statement inside the Actions"?
As long as the condition is false most of the times, else it is slower.

Condition with a single if are supposedly faster but I don't think this is really something to care about unless the event runs VERY frequently.
04-18-2009, 10:36 PM#5
Michael Peppers
Quote:
Originally Posted by Vexorian
As long as the condition is false most of the times, else it is slower.

Condition with a single if are supposedly faster but I don't think this is really something to care about unless the event runs VERY frequently.
Thanks, Vex, so now I suppose I can continue coding this way in my projects without risking to be beaten with a stick. Yay!