SA-MP Forums Archive
[Ajuda] error 002: only a single statement (or expression) can follow each "case" - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] error 002: only a single statement (or expression) can follow each "case" (/showthread.php?tid=596882)



error 002: only a single statement (or expression) can follow each "case" - DKDarkking - 23.12.2015

PHP код:
D:\UNIPORTANTES\PenDrive\Pen Draivi\SA-MP\Estou Fazendo\gamemodes\gm.pwn(797) : error 002only a single statement (or expressioncan follow each "case" 
linhajs
PHP код:

public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_REGISTER:
        {
            if(
strlen(inputtext) < 2){
            new 
string[128];
                 
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD,"! REGISTER"string"Register","Quit");
        } else{
        new 
query[1024], name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridnameMAX_PLAYER_NAME);
        
format(querysizeof(query), "INSERT INTO `apocalypse` (username, password) VALUES ('%s', '%s')"nameinputtext);
        
mysql_function_query(mysqlqueryfalse"","");
        }
    }
    return 
1;




Re: error 002: only a single statement (or expression) can follow each "case" - SaDaN - 23.12.2015

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 
{ 
    switch(dialogid) 
    { 
        case 0: DIALOG_REGISTER: 
        { 
            if(strlen(inputtext) < 2){ 
            new string[128]; 
                 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"! REGISTER", string, "Register","Quit"); 

        } else{ 
        new query[1024], name[MAX_PLAYER_NAME]; 
        GetPlayerName(playerid, name, MAX_PLAYER_NAME); 
        format(query, sizeof(query), "INSERT INTO `apocalypse` (username, password) VALUES ('%s', '%s')", name, inputtext); 
        mysql_function_query(mysql, query, false, "",""); 
        } 
    } 
    return 1; 
}



Re: error 002: only a single statement (or expression) can follow each "case" - EditPawn - 23.12.2015

Switch nгo se pode utilizar if, else if e else para verificar o valor da variбvel. A 'case' tem funзгo jб de substituir essas verificaзхes, deve-se utilizar dessa forma:

PHP код:
new rand random(9);
switch(
rand) {
    case 
0: print("rand й igual a zero.");
    case 
3: print("rand й igual a trкs.");
    case 
5: print("rand й igual a cinco.");
    default: print(
"rand й diferente de zero, trкs e cinco.");

Acesse para entender como funciona a switch
https://sampwiki.blast.hk/wiki/Control_Structures#switch


Re: error 002: only a single statement (or expression) can follow each "case" - DKDarkking - 23.12.2015

Quote:
Originally Posted by SaDaN
Посмотреть сообщение
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 
{ 
    switch(dialogid) 
    { 
        case 0: DIALOG_REGISTER: 
        { 
            if(strlen(inputtext) < 2){ 
            new string[128]; 
                 ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"! REGISTER", string, "Register","Quit"); 

        } else{ 
        new query[1024], name[MAX_PLAYER_NAME]; 
        GetPlayerName(playerid, name, MAX_PLAYER_NAME); 
        format(query, sizeof(query), "INSERT INTO `apocalypse` (username, password) VALUES ('%s', '%s')", name, inputtext); 
        mysql_function_query(mysql, query, false, "",""); 
        } 
    } 
    return 1; 
}
ja resolvi man , seu codigo nгo funcionou mas vlw pela ajuda
fiz assim

PHP код:
    if(dialogid == DIALOG_REGISTER)
    {
        if(
response)
        {