Optional Parameter In Public Functions - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Optional Parameter In Public Functions (
/showthread.php?tid=208144)
Optional Parameter In Public Functions -
Scenario - 07.01.2011
Evening... I have never really needed to know, until now. I have this public function:
pawn Код:
public SendAdminMessage(color, string[])
How do I add an optional parameter after "string[]"?
Re: Optional Parameter In Public Functions -
Retardedwolf - 07.01.2011
For a example to send admin message to certain levels.
pawn Код:
public SendAdminMessage ( color, string [ ], aLvl = -1 )
Which also means if you don't enter a parameter for the aLvl it will be automatically -1 and you could send it to all admin levels.
Re: Optional Parameter In Public Functions -
Scenario - 07.01.2011
Quote:
Originally Posted by Retardedwolf
For a example to send admin message to certain levels.
pawn Код:
public SendAdminMessage ( color, string [ ], aLvl = -1 )
Which also means if you don't enter a parameter for the aLvl it will be automatically -1 and you could send it to all admin levels.
|
Okay, that makes sense. Thank you for that, I really appreciate it!
Re: Optional Parameter In Public Functions -
Scenario - 07.01.2011
Okay, so I have this:
pawn Код:
forward SendAdminMessage(color, string[], sound = 1);
public SendAdminMessage(color, string[], sound = 1)
... and I get these errors:
Код:
C:\Users\Nick\Documents\Relentless Gaming\samp03\gamemodes\RG-CNR.pwn(3844) : error 059: function argument may not have a default value (variable "sound")
C:\Users\Nick\Documents\Relentless Gaming\samp03\gamemodes\RG-CNR.pwn(3845) : error 059: function argument may not have a default value (variable "sound")
Re: Optional Parameter In Public Functions -
bigcomfycouch - 07.01.2011
I don't think public functions are able to have optional parameters.
Re: Optional Parameter In Public Functions -
Scenario - 07.01.2011
Quote:
Originally Posted by bigcomfycouch
I don't think public functions are able to have optional parameters.
|
What about a stock function?
Re: Optional Parameter In Public Functions -
bigcomfycouch - 07.01.2011
Yes, you can do it in a stock.
Re: Optional Parameter In Public Functions -
Joe Staff - 07.01.2011
Yeah stock can have a preset optional, but if it needs to be a public you can just set it when you use it.
Re: Optional Parameter In Public Functions -
Retardedwolf - 07.01.2011
I never knew that cause I mostly used stock functions sorry mate.
Re: Optional Parameter In Public Functions -
Scenario - 07.01.2011
Okay, code wise I have no errors making the two public functions I have into stocks. Perhaps one of you knows the difference between publics and stocks? Thank you for the help, by the way!
Quote:
Originally Posted by Retardedwolf
I never knew that cause I mostly used stock functions sorry mate.
|
Hey, no worries!