HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Is it a good method for customs spells ?

08-07-2008, 09:12 AM#1
Troll-Brain
Instead of doing that :

Collapse JASS:
scope CustomSpellA initializer init
    
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId()=='A000' // id of the custom spell
    endfunction
    
    private function Actions takes nothing returns nothing
        // some stuff
    endfunction
    
    private function init takes nothing returns nothing
        local trigger trig= CreateTrigger()
        call TriggerAddCondition(trig,Condition(function Conditions))
        call TriggerAddAction(trig,function Actions)
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    endfunction

endscope

And so one for all custom spells.

Collapse JASS:
globals
    constant integer ID_CustomSpell_Min= '' // the min id possible of a custom ability
    constant integer ID_CustomSpell_Max= '' // the max id of a possible custom ability
    constant string PREFIX_CUSTOMS_SPELLS = "PCS_"
endglobals

scope CustomSpells initializer init

    globals
        private integer Id
    endglobals
    
    private function Conditions takes nothing returns boolean
        set Id= GetSpellAbilityId()
        if (Id <= ID_CustomSpell_Max) and  (Id >= ID_CustomSpell_Min) then
           call ExecuteFunc(PREFIX_CUSTOMS_SPELLS+I2S(Id))
        endif
        return false
    endfunction
    
    private function init takes nothing returns nothing
        local trigger trig= CreateTrigger()
        call TriggerAddCondition(trig,Condition(function Conditions))
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    endfunction
    
endscope

And then :

Collapse JASS:
    function PCS_40960 takes nothing returns nothing // 40960 == 'A000'
        // some stuff
    endfunction

I know ExecuteFunc is slow and I2S quite too.
But if you have lot of customs spells it could be an alternative, or not ?

I'm not talking about the ugliness coding, just about the performance issue.
I know that is silly and requires to change the id perfectly.

And maybe we should have issues with the optimizer if we use it badly.

What you think about that ?

Because of the using of ExecuteFunc i'm not sure we can do that.
Plz say me if i'm wrong.

And i though also for the function GetObjectName, but if we want to make the map for many langages, then it can't be done.
08-07-2008, 10:18 AM#2
Pyrogasm
Doesn't call ExecuteFunc("SomeFunctionThatDoesn'tExist") crash the game?

Seems like it'd be a pretty risky way of doing things.
08-07-2008, 10:19 AM#3
cohadar
Quote:
Originally Posted by Troll-Brain
Plz say me if i'm wrong.
You are wrong.
08-07-2008, 10:19 AM#4
Pyrogasm
Me or him?
08-07-2008, 10:50 AM#5
Troll-Brain
He quote me so he says i'm wrong.
And yes if the function doesn't exist it's crash but i didn't said that's the easiest way :p

But it will be so slow ?
08-07-2008, 11:23 AM#6
d07.RiV
I doubt it will be slower than having a hundred triggers so yes, its a possible way. Only I2S will not give you an ID-like string, instead it will be more like "1231415". If you don't forget anything it will work.
But it is a bad way of doing things, don't bother with opimizing the number of triggers. You can create a textmacro for doing that instead if you want to save your own time.
Also vxmapopt will not work with concatenated string passed to ExecuteFunc so you will have to put every handler function as an exception in the optimizer options and it takes a while.
08-07-2008, 11:29 AM#7
Troll-Brain
Quote:
Originally Posted by d07.RiV
I doubt it will be slower than having a hundred triggers so yes, its a possible way. Only I2S will not give you an ID-like string, instead it will be more like "1231415". If you don't forget anything it will work.
But it is a bad way of doing things, don't bother with opimizing the number of triggers. You can create a textmacro for doing that instead if you want to save your own time.
Also vxmapopt will not work with concatenated string passed to ExecuteFunc so you will have to put every handler function as an exception in the optimizer options and it takes a while.
Oh yes i've forgotten that i must use the ten base for the functions name.
Thx
08-07-2008, 11:43 AM#8
d07.RiV
And function names can't start with a digit so you will have to concatenate stuff :p

Just avoid it, you cant get a lag this way, all those functions are fast enough. And, don't use actions because they're useless. Just put everything into conditions, it will be faster (and make it return false).
08-07-2008, 11:50 AM#9
Troll-Brain
Quote:
Originally Posted by d07.RiV
And function names can't start with a digit so you will have to concatenate stuff :p

Just avoid it, you cant get a lag this way, all those functions are fast enough. And, don't use actions because they're useless. Just put everything into conditions, it will be faster (and make it return false).

The name is not really a problem i can add a prefix easily.
You can't do, waits, pause game, and so one on conditions.

Anyway i don't think i will use it, that's just for the knowledge :p
08-07-2008, 12:31 PM#10
d07.RiV
Don't use waits at all, use timers.
And you don't need pause game in every trigger ><
08-07-2008, 12:35 PM#11
Troll-Brain
Quote:
Originally Posted by d07.RiV
Don't use waits at all, use timers.
In few cases, a wait is enough if you don't need precision.
But don't worry i already abuse timers.
Quote:
Originally Posted by d07.RiV
And you don't need pause game in every trigger ><
Oh really ?
Just talking about what we can't do on a condition, that's all.