AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Letting an optional parameter die? (https://forums.alliedmods.net/showthread.php?t=282814)

tenub 05-17-2016 22:20

Letting an optional parameter die?
 
I wish to call this function with or without a second parameter. With it, I care about setting its value and would be able to test the value of the message from an outside function. Without it, I don't care and would simply like the return value (which will be returned in either case and is an integer, respType):

PHP Code:

stock parse_resp_data(data[], message[] = 0)
{
    new 
respTypeerror[512], errorSize sizeof(error);

    if (!
strlen(message))
    {
        new 
message[512];
    }

    switch (
data[0])
    {
        case 
'+': { respType parse_resp_simple_string(data[1], message); }

        ...

    }

    return 
respType;


Is this possible?

Black Rose 05-18-2016 11:48

Re: Letting an optional parameter die?
 
If you make it a native with style 0, you can see how many parameters was sent and react to that.
Code:
native parse_resp_data(data[], ...) // ... public plugin_natives()     register_native("parse_resp_data", "native_parse_resp_data") public native_parse_resp_data(PluginID, NumParams) {     // ...     switch ( NumParams ) {         case 2: server_print("Using message")         case 1: server_print("Not using message")         default: server_print("Failure");     }     //... }
Another option is to set the default value to something weird that you wouldn't find in whatever the user enters and checking if the parameter is equal to that weird value or empty.
Code:
stock parse_resp_data(data[], message[] = "^1") {     // ...     if ( message[0] != '^1' )         server_print("Using message")     else         server_print("Not using message")     // ...
I think I understood you correctly but I'm not really sure.

On a side note, I saw your latest post and started making an API for RESP. But if you do it instead, that's probably for the best.
Add me to Steam if you need someone to bounce ideas with. http://steamcommunity.com/id/IIlllIllIlll


All times are GMT -4. The time now is 18:33.

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