Raised This Month: $ Target: $400
 0% 

Calling a function by string


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
PreDominance
Member
Join Date: Jul 2014
Old 08-10-2014 , 03:44   Re: Calling a function by string
Reply With Quote #3

It actually has nothing to do with my other thread; I was going to have races coded 100% externally (now I'm just parsing through race configuration data, looks pretty though!). This one is referring to executing functions.

Let me clarify my problem for you then (I tried to in my first post), to avoid the XY problem. I'll assume you have a basic understand of a warcraft mod.

Each race in my mod is nothing more than an .inl file with functions and declarations. Each race file needs to have functions that need to be executed based on various events. These events are basic: player_attack, player_spawn, player_jump, etc.
Here's the question: how do you know which event to execute? Each player has nothing more than a number to discern his/her race. I can do something like:
PHP Code:
public event_player_killed(victimattackershouldgib
{
    
nwc_checkChangeRace(victim);
    if (
P_DATA[attacker][PB_HAS_ATTACK]) {
        switch(
P_DATA[attacker][P_RACE]) {
            case 
EVERY_RACE_WITH_ATTACK_SKILL?!
        }
    }

However, if I can simply format a function call, I can (knowing beforehand that I've formatted the function names correctly) merely do this:
PHP Code:
public event_player_killed(victimattackershouldgib
{
    
nwc_checkChangeRace(victim);
    if (
P_DATA[attacker][PB_HAS_ATTACK]) {
        new 
szAttackSkill[50];
        
format(szAttackSkillcharsmax(szAttackSkill), "%i_attack"P_DATA[attacker][P_RACE]);
        
callFunc(szAttackSkill);
    }

*Edit

So after more snooping I found the callfunc native. Why would this not be the perfect solution? Let's find out & read some more.

Last edited by PreDominance; 08-10-2014 at 04:11.
PreDominance is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode