Raised This Month: $ Target: $400
 0% 

Default argument


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-16-2012 , 11:53   Default argument
Reply With Quote #1

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?
Liverwiz is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-16-2012 , 11:56   Re: Default argument
Reply With Quote #2

You should be able to go:

PHP Code:
public MyFunctionArg1any:... ) 
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-16-2012 , 11:58   Re: Default argument
Reply With Quote #3

Make it non-public, like:

PHP Code:
function_name(param1,param2 1337// default value for param2 is 1337 
__________________

Last edited by <VeCo>; 05-16-2012 at 11:59.
<VeCo> is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-16-2012 , 12:02   Re: Default argument
Reply With Quote #4

Quote:
Originally Posted by <VeCo> View Post
Make it non-public, like:

PHP Code:
function_name(param1,param2 1337// default value for param2 is 1337 
Oh I never realised that worked.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-16-2012 , 12:16   Re: Default argument
Reply With Quote #5

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" ?

Last edited by Liverwiz; 05-16-2012 at 12:17.
Liverwiz is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-16-2012 , 12:20   Re: Default argument
Reply With Quote #6

Yes, you could try it.
__________________
<VeCo> is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-16-2012 , 12:23   Re: Default argument
Reply With Quote #7

Quote:
Originally Posted by <VeCo> View Post
Yes, you could try it.
well....it compiled.
Liverwiz is offline
Reply


Thread Tools
Display Modes

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 00:32.


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