functions and vars
Hello, I would like to know if I can store function in variable to then call directly from it, something like the following
Code:
I need this because I'm working with a large number of functions, so would be more easy to store the function and call it directly instead of use "switch" and/or "if/else if". |
Re: functions and vars
No you cant, variable is not a function.
|
Re: functions and vars
get_func_id() + callfunc_begin_i()
|
Re: functions and vars
I think I understood correctly, here is an example.
Code:
Then: Code:
|
Re: functions and vars
The function is just an example actually. Anyway, I will have to opt for switch case.
|
Re: functions and vars
There are no pointers in pawn, so you can't do that directly. However, you can do as OciXCrom said and use callfuncs.
If the syntax is ugly or you want to keep it short, you can always create a macro or wrapper function that will do all the callfunc logic: callfunc_begin + push + end. Such function should take as the first argument an enum which will determine what function to call(that is assuming all your functions that need to be called have the same header). |
Re: functions and vars
It sounds like you are just trying to make it so that you just write less code. If this is the case, you should really rethink this approach. You shouldn't try to do something like this just because you want to write less code. You need to have some other significant reason.
I bet that you could architect your code better so that it's not as bad as you think it is going to be. However, we can't help you with that since you've not given any information about what you are actually trying to do. |
| All times are GMT -4. The time now is 07:31. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.