Help me skip a parameter! -
DuyDang2412 - 23.07.2017
Hi guys, I want to skip parameter 'color' in this function because it's optional so I don't want to set it to COLOR_YELLOW again. I just set it to another color when I need.
PHP код:
SendAdminAlert(color = COLOR_YELLOW, message[])
{
foreach(new i: Player)
{
if(!Character[i][Admin]) continue;
Scm(i, color, message);
}
return 1;
}
Please help me. Thanks in advanced.
Re: Help me skip a parameter! -
OneDay - 23.07.2017
PHP код:
SendAdminAlert(message[], color = COLOR_YELLOW)
Re: Help me skip a parameter! -
GaByM - 23.07.2017
You can change the parameters order, as OneDay said, or you can call your function like this:
PHP код:
OnPlayerConnect(playerid)
{
SendAdminAlert(.message="A player joined the server.");
return 1;
}
Re: Help me skip a parameter! -
DuyDang2412 - 23.07.2017
Thanks a lot!
Quote:
Originally Posted by GaByM
You can change the parameters order, as OneDay said, or you can call your function like this:
PHP код:
OnPlayerConnect(playerid)
{
SendAdminAlert(.message="A player joined the server.");
return 1;
}
|
Why
Quote:
SendAdminAlert(.message="A player joined the server.");
|
But not
Quote:
SendAdminAlert("A player joined the server.");
|
??
Re: Help me skip a parameter! -
GaByM - 24.07.2017
Because "A player joined the server." is passed as the first parameter by default, unless otherwise specified.
That's why you use .message="..".
A better example is this
PHP код:
CreateVehicle(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay, addsiren=0);
In this function you first place the vehicletype, then x, y, z, a, etc..
If you want to change the parameters order you simply can do this:
PHP код:
CreateVehicle(.z=3.0, .x=0.0, .y=15.0, .vehicletype=411, etc..);
And it will spawn an infernus (model 411) at X: 0.0, Y: 15.0, Z: 3.0
But in your case it is better to just swap the function arguments so the function will look like this
PHP код:
SendAdminAlert(message[], color = COLOR_YELLOW)
{
foreach(new i: Player)
{
if(!Character[i][Admin]) continue;
Scm(i, color, message);
}
return 1;
}
The first parameter will be the message (it's required) and the second one will be the color (which if not specified, it will be by default COLOR_YELLOW)