[Ajuda] Loop
#1

pawn Код:
Teste(playerid)
{
    for(new x; x < 5; ++x)
    {
        if(strcmp(Clan[x], "Nenhum", true) != 0) continue;
        {
            new teste[128];
            format(teste, sizeof(teste), "Slot clan %d liberado", x);
            MsgToPlayer(teste);
            break;
        }
    }
}
Como fazer para caso se nenhuma "if" seja chamada no loop retornar a uma mensagem de erro?
Espero que alguma alma me ajude
Reply
#2

Nгo entendi muito bem, mais acho que nгo deveria por um "else" ?
Reply
#3

pawn Код:
Teste(playerid)
{
    for(new x; x < 5; ++x)
    {
        if(strcmp(Clan[x], "Nenhum", true) != 0) SendClientMessage(playerid, -1, "Erro");
        {
            new teste[128];
            format(teste, sizeof(teste), "Slot clan %d liberado", x);
            MsgToPlayer(teste);
            break;
        }
    }
}
Reply
#4

assim?

pawn Код:
Teste(playerid)
{    
    for(new x; x < 5; ++x)
    {
        if(!strcmp(Clan[x], "Nenhum", true))
        {  
            new teste[128];
            format(teste, sizeof(teste), "Slot clan %d liberado", x);
            MsgToPlayer(teste);
            break;
        }
       
        if(x == 4) //ULTIMO numero do loop
            MsgToPlayer("ERROR: Nada liberado '-'");
    }
}
Reply
#5

pawn Код:
Teste(playerid)
{
    for(new x; x < 5; ++x)
    {
        if(strcmp(Clan[x], "Nenhum", true) != 0) continue;
        {
            new teste[128];
            format(teste, sizeof(teste), "Slot clan %d liberado", x);
            MsgToPlayer(teste);
            break;
        }
    }
    else
    {
          SendClientMessage(playerid, -1, "Erro");
    }
}
Reply
#6

pawn Код:
Teste(playerid)
{    
    for(new x; x < 5; ++x)
    {
        if(strcmp(Clan[x], "Nenhum", true) == 0) break;  
        new teste[128];
        format(teste, sizeof(teste), "Slot clan %d liberado", x);
        MsgToPlayer(teste);
        break;
    }

}
Reply
#7

else em loop? #failmaster
Reply
#8

Else em loop?
Vocкs estгo testando as porcarias que postam aqui?
Reply
#9

#correto:

pawn Код:
Teste(playerid)
{
    for(new x; x < 5; ++x)
    {
        new teste[128];
        if(strcmp(Clan[x], "Nenhum", true) != 0) continue;
        {            
            format(teste, sizeof(teste), "Slot clan %d liberado", x);
            MsgToPlayer(teste);
            break;
        }
        else
        {
          format(teste, sizeof(teste), "Msg de erro para o player");
          MsgToPlayer(teste);
        }
    }    
}
Reply
#10

pawn Код:
Teste(playerid)
{
    new bool: PtLib = true;
    for(new x; x < 5; ++x)
    {
        if(strcmp(Clan[x], "Nenhum", true) != 0) continue;
        {
            PtLib = false;
            new teste[128];
            format(teste, sizeof(teste), "Slot clan %d liberado", x);
            MsgToPlayer(teste);
            break;
        }
    }
    if(PtLib) //Erro
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)