SA-MP Forums Archive
Help me skip a parameter! - 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)
+--- Thread: Help me skip a parameter! (/showthread.php?tid=637886)



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