Dynamic number of arguments in functions
Well we all know how to create a function but what about a function that uses dynamic number of parameters.
I recommend not reading if you do not have basic scripting knowledge. PHP Code:
Well the answer is simple you just need to use these functions: For example for the function that we made above we can do something like this: PHP Code:
That means that the number of parameters can vary. Is this limited only to integer values? No you can also copy vectors, strings, and Float values. Here is a basic example Float example: PHP Code:
PHP Code:
Well for example I used it to create a way for sending text messages more easily. This is what my function looks like: PHP Code:
For example instead of writing: PHP Code:
PHP Code:
Example: PHP Code:
|
Re: Dynamic number of arguments in functions
This is one of the most incomplete tutorials I've ever seen. You should really cover topics such as the vformat() and format_args() functions, which basically do half of the work for you that this tutorial teaches you how to do manually (and unnecessarily except for demonstration).
|
Re: Dynamic number of arguments in functions
Good job OT, this is usefull for me.
|
Re: Dynamic number of arguments in functions
For TextMsg i guess something like HLSDK would be more efficient.
Your tut is still usefull though. PHP Code:
Code:
void ClientPrint( entvars_t *client, int msg_dest, const char *msg_name, const char *param1, const char *param2, const char *param3, const char *param4 ) |
Re: Dynamic number of arguments in functions
I'm using such natives in Server Cvars Unlocker plugin, it helps nicely to have a code more easy and more readable.
Good job, though like Hawk, it's quite short. |
Re: Dynamic number of arguments in functions
Quote:
@all: Thank you! And will update it sooner with more stuff. I wrote it when I was tired. :P |
Re: Dynamic number of arguments in functions
cool tut thnx :D
|
Re: Dynamic number of arguments in functions
How can i do this?
PHP Code:
|
Re: Dynamic number of arguments in functions
Quote:
PHP Code:
PHP Code:
|
Re: Dynamic number of arguments in functions
Thank you both :)
One more thing, can i pass any type of data with func( any: ... ) as long as it is handled properly inside the function without tagging it again when i handle it? For example if i pass a float, int and a bool, to i always have to tag it like this? PHP Code:
|
All times are GMT -4. The time now is 07:24. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.