Why cant compile this ?
#1

PHP код:
CMD:dance(playeridparams[])
{
if(
id == 1)
            {
                
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE1);// Dancing Styles
            
}
            else if(
id == 2)
            {
                
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE2);// Dancing Styles
            
}
            else if(
id == 3)
            {
                
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE3);// Dancing Styles
            
}
            else if(
id == 4)
            {
                
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE4);// Dancing Styles
            
}
            else
            {
                
SendClientMessage(playeridCOLOR_WHITE"USAGE: /an dance [ID]");
                
SendClientMessage(playeridCOLOR_LIGHTBLUE"1,2,3,4");
            }
return 
1;

I got:
PHP код:
C:\Users\Niko\Desktop\DeathMatch server by bustern\gamemodes\DeathMatch.pwn(823) : error 017undefined symbol "id"
C:\Users\Niko\Desktop\DeathMatch server by bustern\gamemodes\DeathMatch.pwn(827) : error 017undefined symbol "id"
C:\Users\Niko\Desktop\DeathMatch server by bustern\gamemodes\DeathMatch.pwn(831) : error 017undefined symbol "id"
C:\Users\Niko\Desktop\DeathMatch server by bustern\gamemodes\DeathMatch.pwn(835) : error 017undefined symbol "id" 
Reply
#2

This will work
pawn Код:
CMD:dance(playerid, params[])
{
new id;
if(id == 1)
            {
                SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE1);// Dancing Styles
            }
            else if(id == 2)
            {
                SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE2);// Dancing Styles
            }
            else if(id == 3)
            {
                SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE3);// Dancing Styles
            }
            else if(id == 4)
            {
                SetPlayerSpecialAction(playerid,SPECIAL_ACTION_DANCE4);// Dancing Styles
            }
            else
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /an dance [ID]");
                SendClientMessage(playerid, COLOR_LIGHTBLUE, "1,2,3,4");
            }
return 1;
}
Reply
#3

No, it definitely will not.

You are creating a variable 'id', but you haven't given it a value. Thus giving it a default value of 0, meaning you will just get the error messages/syntax message every time you use the command, regardless of the parameters you enter. Also, you are missing a bracket which would just create more errors within the script.

The correct code for this would be:
With SSCANF include/plugin (RECOMMENDED):
pawn Код:
CMD:dance(playerid, params[])
{
    new selection;
    if(sscanf(params, "d", selection))
    {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /dance [ID]");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "IDs: 1, 2, 3, 4");
        return 1;
    }
    switch(selection)
    {
        case 1: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE1);
        case 2: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE2);
        case 3: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE3);
        case 4: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE4);
    }
    return 1;
}
Without SSCANF Plugin/Include (NOT RECOMMENDED):
pawn Код:
CMD:dance(playerid, params[])
{
    if(!strlen(params))
    {
        SendClientMessage(playerid, COLOR_WHITE, "USAGE: /dance [ID]");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "IDs: 1, 2, 3, 4");
        return 1;
    }
    new selection = strval(params);
    switch(selection)
    {
        case 1: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE1);
        case 2: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE2);
        case 3: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE3);
        case 4: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE4);
        default:
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /dance [ID]");
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "IDs: 1, 2, 3, 4");
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)