• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[LUA] Are using Trigger Conditions or if statements faster in Lua?

Status
Not open for further replies.
Level 6
Joined
Jul 21, 2020
Messages
67
So, I'm working on changing my map over to Lua and had a performance question about triggers.

Say I have 5 GUI triggers "Unit starts the Effect of an Ability" each having a separate condition and in Lua I'm thinking it would be easier if I have 1 trigger created for that event, and then in the Actions that are added, I add functions for each use that would resolve conditions inside the function.

Something like this:
Lua:
    local t = CreateTrigger()
    TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    TriggerAddAction(
        t,
        function()
            spell1()
            spell2()
            spell3()
            spell4()
        end
    )

Does that make sense? Wondering from a performance perspective if that would be something that would be as fast as doing it the traditional TriggerAddCondition way.
 
If you want the fastest performance possible, everything should be a triggercondition, since those are faster then actions. Having an action + a condition will always be slower than having just one of them and checking conditions using if blocks, since you are starting two threads when you have both and action and a condition.

You'll be hard-pressed to find a practical scenario where there will be a noticeable difference in-game.

For things like triggered abilties where the only condition is "GetTriggerAbilityId() == your_id" the best thing you can do is to have 1 single trigger, and then a table that maps an ability id to a function. Then when that trigger is executed, execute the function in the table that is stored in the key of the ability that was cast:

"ability_handler_functions[your_id]()"
 
Status
Not open for further replies.
Top