Optional Parameter In Public Functions
#1

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[]"?
Reply
#2

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.
Reply
#3

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!
Reply
#4

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")
Reply
#5

I don't think public functions are able to have optional parameters.
Reply
#6

Quote:
Originally Posted by bigcomfycouch
Посмотреть сообщение
I don't think public functions are able to have optional parameters.
What about a stock function?
Reply
#7

Yes, you can do it in a stock.
Reply
#8

Yeah stock can have a preset optional, but if it needs to be a public you can just set it when you use it.
Reply
#9

I never knew that cause I mostly used stock functions sorry mate.
Reply
#10

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!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)