Help me skip a parameter!
#1

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_YELLOWmessage[])
{
    foreach(new 
iPlayer)
    {
        if(!
Character[i][Admin]) continue;
        
Scm(icolormessage);
    }
    return 
1;

Please help me. Thanks in advanced.
Reply
#2

PHP код:
SendAdminAlert(message[], color COLOR_YELLOW
Reply
#3

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;

Reply
#4

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.");

??
Reply
#5

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(vehicletypeFloat:xFloat:yFloat:zFloat:rotationcolor1color2respawn_delayaddsiren=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=411etc..); 
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 
iPlayer
    { 
        if(!
Character[i][Admin]) continue; 
        
Scm(icolormessage); 
    } 
    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)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)