Raised This Month: $ Target: $400
 0% 

Letting an optional parameter die?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tenub
Junior Member
Join Date: Aug 2013
Old 05-17-2016 , 22:20   Letting an optional parameter die?
Reply With Quote #1

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?
tenub is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-18-2016 , 11:48   Re: Letting an optional parameter die?
Reply With Quote #2

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
__________________

Last edited by Black Rose; 05-18-2016 at 12:17.
Black Rose is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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