AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Default argument (https://forums.alliedmods.net/showthread.php?t=185373)

Liverwiz 05-16-2012 11:53

Default argument
 
I'm writing a function that needs to be able to be called with or without a second argument. How do i make that accepted?

hornet 05-16-2012 11:56

Re: Default argument
 
You should be able to go:

PHP Code:

public MyFunctionArg1any:... ) 


<VeCo> 05-16-2012 11:58

Re: Default argument
 
Make it non-public, like:

PHP Code:

function_name(param1,param2 1337// default value for param2 is 1337 


hornet 05-16-2012 12:02

Re: Default argument
 
Quote:

Originally Posted by <VeCo> (Post 1710023)
Make it non-public, like:

PHP Code:

function_name(param1,param2 1337// default value for param2 is 1337 


Oh I never realised that worked.

Liverwiz 05-16-2012 12:16

Re: Default argument
 
The thing is i have the second argument used within the function. Here's my code....

Code:

stock resetLevel(id, reason[])
{
        g_playerFrags[id] = 5
        client_print_color(id, DontChange, "^3[AMX] ^1Your level has been set to 5 for %s", reason)
        return 5
}

Should i make it like reason[] = "no reason given" ?

<VeCo> 05-16-2012 12:20

Re: Default argument
 
Yes, you could try it.

Liverwiz 05-16-2012 12:23

Re: Default argument
 
Quote:

Originally Posted by <VeCo> (Post 1710051)
Yes, you could try it.

well....it compiled.


All times are GMT -4. The time now is 00:32.

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