AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Method Parameters (https://forums.alliedmods.net/showthread.php?t=64889)

Minimum 12-26-2007 19:28

Method Parameters
 
I noticed with methods such as server_print that there is this parameter at the end described as "any:...". I was wondering if I could put this into any methods I make. I tried just passing a string in and I was met with an error saying the string is incorrectly formatted. This error occurred on the line with server_print. Code:

Code:
public printMsg(const message[],any:...) {      server_print(message);     return PLUGIN_CONTINUE; }

Code:
new name[32] = "SchmoSalt"; printMsg("Your name is %s.",name);

Arkshine 12-26-2007 19:48

Re: Method Parameters
 
Well ,in you example, it should be enough :

Code:
new name[32] = "SchmoSalt"; server_print( "Your name is %s.", name );

Anyway, you have to use vformat() to get parameters. Something like:

Code:
my_function( id ) {     new name[32] = "SchmoSalt";     printMsg( id, "Your name is %s.", name ); } printMsg( id, const sMsg[], any:... ) {     static sNew_msg[191];     vformat( sNew_msg, charsmax( sNew_msg ), sMsg, 3 );         client_print( id, print_chat, sNew_msg ); }

Minimum 12-26-2007 19:54

Re: Method Parameters
 
That works flawlessly. Thanks for the quick and accurate reply!

+karma for you.


All times are GMT -4. The time now is 11:08.

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