Calling a function by string
Greetings,
In making my warcraft mod, I'm stuck with "how do I call a player's race_attack skill, with abstraction as key?". The easiest way would be to have the player's race_attack skill have a specific format (#RACENUM#_skill_attack_#NUM#), and then call that function via a formatted string. The only way I know to call a function via a formatted string is by set_task. However I need to execute that function immediately, not 0.1 seconds after (0.1 seconds is fine for spawn-related functions, but I need immediate results when it comes to player_hurt). So, how do I do something like the following: PHP Code:
|
Re: Calling a function by string
A question like this makes me think that you need to do a redesign of your overall program architecture, I believe this is an "XY Problem". It also seems that this is a continuation of this thread.
If you would like any good advice on what to do instead of what you are doing, you'll need to explain what exactly you are trying to do (without mentioning specific code) i.e. the overall design of your program. At first glance, I would have to say it will probably be related to multiforwards or something similar. |
Re: Calling a function by string
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:
PHP Code:
So after more snooping I found the callfunc native. Why would this not be the perfect solution? Let's find out & read some more. |
Re: Calling a function by string
Inline files are not for building API's like you are trying to do. If you use inline files, you are essentially hardcoding everything, they are only useful for organizing your code. If you are actually wanting to make things dynamic, you need to build an API that allows you to "register" your race which sets up multiforwards for your race specific actions.
|
Re: Calling a function by string
Hawk552 also told me this as an alternative, and maybe I'll look into it at another time. For now, I have exactly 6 days to get a beta version of this mod out and running because I'll be heading back to school wherein I need time to move back in, see old friends, drink, and actually do school. I hate to sound ignorant but I really don't have time to redesign everything I've done so far.
Can you tell me why the callfunc native wouldn't be ideal? |
Re: Calling a function by string
Without reading the entire thread, this is how you can call a function.
Code:
|
Re: Calling a function by string
Thank you Kia, I did find it but only recently. This opens up a world of opportunities, though.
|
| All times are GMT -4. The time now is 12:58. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.