[Ajuda] Problema com o looping
#1

Iai galera beleza, bom eu to tendo um problema com meu looping. eu to fazendo um sistema de keys e no comando para ver todas as keys existentes mesmo existindo varias keys ele me diz que nгo existe nenhuma key, como eu to criando um arquivo para cada key eu precisei fazer um loop para carregar todos os arquiivos, porйm, mesmo com o loop verificando se o arquivo existe ou nгo ele sempre esta dizendo que nenhuma key existe, eu estou achando que seja o loop, serб que voces podem me ajudar?

pawn Code:
CMD:verkeys(playerid)
{
    new string[300];
    for(new i; i < 3000; i++)
    {
        format(String, sizeof(String), CONTAS, string[i]);
        if(DOF2::FileExists(String))
        {
            format(String2, sizeof(String2), "%s %s\n", String2, string[i]);
            ShowPlayerDialog(playerid, DIALOGNORESPONSE, DIALOG_STYLE_MSGBOX, "Keys existentes", String2, "Ok", "");
        }
        else return SendClientMessage(playerid, -1, "Nгo existe nenhuma key!");
    }
    return 1;
}
Reply
#2

tire a dialog de dentro do loop

PHP Code:
CMD:verkeys(playerid)
{
    new 
string[300];
    for(new 
i3000i++)
    {
        
format(Stringsizeof(String), CONTASstring[i]);
        if(
DOF2::FileExists(String))
        {
            
format(String2sizeof(String2), "%s %s\n"String2string[i]);
        }
        else return 
SendClientMessage(playerid, -1"Nгo existe nenhuma key!");
    }
    
ShowPlayerDialog(playeridDIALOGNORESPONSEDIALOG_STYLE_MSGBOX"Keys existentes"String2"Ok""");
    return 
1;

Reply
#3

Quote:
Originally Posted by moura98
View Post
tire a dialog de dentro do loop

PHP Code:
CMD:verkeys(playerid)
{
    new 
string[300];
    for(new 
i3000i++)
    {
        
format(Stringsizeof(String), CONTASstring[i]);
        if(
DOF2::FileExists(String))
        {
            
format(String2sizeof(String2), "%s %s\n"String2string[i]);
        }
        else return 
SendClientMessage(playerid, -1"Nгo existe nenhuma key!");
    }
    
ShowPlayerDialog(playeridDIALOGNORESPONSEDIALOG_STYLE_MSGBOX"Keys existentes"String2"Ok""");
    return 
1;

Já tentei tbm, porém continua a mesma coisa, mesmo existindo vários arquivos me retorna a mensagem dizendo que não existe nenhum, sera que eu fiz o loop errado?
Reply
#4

tenta assim

PHP Code:
CMD:verkeys(playerid

    new 
string[300]; 
    for(new 
i3000i++) 
    { 
        
format(Stringsizeof(String), CONTASstring[i]); 
        if(
DOF2::FileExists(String)) 
        { 
            
format(String2sizeof(String2), "%s %s\n"String2string[i]); 
            
strcat(String2String2);
        } 
        else return 
SendClientMessage(playerid, -1"Nгo existe nenhuma key!"); 
    } 
    
ShowPlayerDialog(playeridDIALOGNORESPONSEDIALOG_STYLE_MSGBOX"Keys existentes"String2"Ok"""); 
    return 
1

Reply
#5

Quote:
Originally Posted by moura98
View Post
tenta assim

PHP Code:
CMD:verkeys(playerid

    new 
string[300]; 
    for(new 
i3000i++) 
    { 
        
format(Stringsizeof(String), CONTASstring[i]); 
        if(
DOF2::FileExists(String)) 
        { 
            
format(String2sizeof(String2), "%s %s\n"String2string[i]); 
            
strcat(String2String2);
        } 
        else return 
SendClientMessage(playerid, -1"Nгo existe nenhuma key!"); 
    } 
    
ShowPlayerDialog(playeridDIALOGNORESPONSEDIALOG_STYLE_MSGBOX"Keys existentes"String2"Ok"""); 
    return 
1

Continuar a mesma coisa, ainda й como se nгo houvesse nenhuma key :/
Reply
#6

O return dentro do loop acaba com o loop. Tem que usar continue para continuar no proximo indice do loop.
Mas no seu caso basta remover a palavra return.
E tambйm tem que colocar algo ali, no loop vc requisita uma variavel chamada String e uma String2, ambas nгo foram inicializadas dentro do comando...

PHP Code:
else
{
    
SendClientMessage(playerid, -1"Nгo existe nenhuma key!");
    
// continue;  // continue aqui, mas й inutil jб que nгo tem mais codigo abaixo. 

PHP Code:
CMD:verkeys(playerid)
{
    new 
string[300], string2[300], result false;
    for(new 
i3000i++)
    {
        
format(stringsizeof(string), CONTASstring[i]);
        if(
DOF2::FileExists(string))
        {
            
format(string2sizeof(string2), "%s %s\n"string2string[i]);
            
strcat(string2string2);
            
result true;
        }
    }
    if (
result == false)
        return 
SendClientMessage(playerid, -1"Nгo existe nenhuma key!");
    else
        
ShowPlayerDialog(playeridDIALOGNORESPONSEDIALOG_STYLE_MSGBOX"Keys existentes"string2"Ok""");
    return 
1;

Reply
#7

Quote:
Originally Posted by RenanMsV
View Post
O return dentro do loop acaba com o loop. Tem que usar continue para continuar no proximo indice do loop.
Mas no seu caso basta remover a palavra return.
E tambйm tem que colocar algo ali, no loop vc requisita uma variavel chamada String e uma String2, ambas nгo foram inicializadas dentro do comando...

PHP Code:
else
{
    
SendClientMessage(playerid, -1"Nгo existe nenhuma key!");
    
// continue;  // continue aqui, mas й inutil jб que nгo tem mais codigo abaixo. 

PHP Code:
CMD:verkeys(playerid)
{
    new 
string[300], string2[300], result false;
    for(new 
i3000i++)
    {
        
format(stringsizeof(string), CONTASstring[i]);
        if(
DOF2::FileExists(string))
        {
            
format(string2sizeof(string2), "%s %s\n"string2string[i]);
            
strcat(string2string2);
            
result true;
        }
    }
    if (
result == false)
        return 
SendClientMessage(playerid, -1"Nгo existe nenhuma key!");
    else
        
ShowPlayerDialog(playeridDIALOGNORESPONSEDIALOG_STYLE_MSGBOX"Keys existentes"string2"Ok""");
    return 
1;

Ta nem reconhecendo o comando agora '-', sу ta dando
pawn Code:
SERVER:Unkown Command
Reply
#8

Code:
	new string[300];
	for(new i; i < 3000; i++)
	{
		format(String, sizeof(String), CONTAS, string[i]);
wtf
Reply
#9

Quote:
Originally Posted by 1sbedx
View Post
Code:
	new string[300];
	for(new i; i < 3000; i++)
	{
		format(String, sizeof(String), CONTAS, string[i]);
wtf
o que й que ta errado ai? ainda nгo sei bem como fazer loop para strings.
Reply
#10

Estб td errado, vocк estб formatando a prуpria string, sendo que nгo tem nada nela, wtffff.

PHP Code:
format(stringsizeof(string), CONTASi); 
Se a contas for em nomes vai ser outra fita.
Reply
#11

Quote:
Originally Posted by Felipealves
View Post
Estб td errado, vocк estб formatando a prуpria string, sendo que nгo tem nada nela, wtffff.

PHP Code:
format(stringsizeof(string), CONTASi); 
Se a contas for em nomes vai ser outra fita.
Qual seria a melhor forma de fazer este comando? Eu nгo sabia por onde comeзar e acabei fazendo dessa forma.
Reply
#12

Depende, vocк ta salvando os arquivos com nomes ou nъmeros?
Reply
#13

Quote:
Originally Posted by Felipealves
View Post
Depende, vocк ta salvando os arquivos com nomes ou nъmeros?
Com nomes e nъmeros, o nome do arquivo й a prуpria key, por isso tenho que usar string.
Reply
#14

Se for com nъmeros faзa assim.

Se for letras/nomes, vocк vai ser complicado e nгo vai compensar a gambiarra, enfim, se for letras/nomes,
aconselho usar mysql.
PHP Code:
CMD:verkeys(playerid){
    new 
file[64], // vai armazena a conta, nгo me lembro se й preciso de td isso qualquer coisa diminua.
        
string_2[24+15], // armazena o nome e o int
        
string_3[900], // vai juntar todas contas atй o 100, precisa aumentar ou diminuir se for preciso.
        
count
    
;
    for(new 
0100i++){
        
format(filesizeof(file), CONTASi);
        if(
DOF2::FileExists(string)){
            
format(string_2sizeof(string_2), "%d [%s]\n"iDOF2::GetString(file"Nome"));
            
strcat(string_3string_2);
            
count++; // vai ser incrementado caso exista.
        
}
    }
    
printf("%d"strlen(string_3)); // se der 899 й pq nгo cabem mais e precisa aumentar...
    
if(!count){
        return 
SendClientMessage(playerid, -1"Nenhuma Key foi encontrada!");
    }else{
        
ShowPlayerDialog(playeridDIALOGNORESPONSEDIALOG_STYLE_MSGBOX"Keys existentes"string_3"Ok""");
    }
    return 
1;

Reply
#15

Quote:
Originally Posted by Felipealves
View Post
Se for com nъmeros faзa assim.

Se for letras/nomes, vocк vai ser complicado e nгo vai compensar a gambiarra, enfim, se for letras/nomes,
aconselho usar mysql.
PHP Code:
CMD:verkeys(playerid){
    new 
file[64], // vai armazena a conta, nгo me lembro se й preciso de td isso qualquer coisa diminua.
        
string_2[24+15], // armazena o nome e o int
        
string_3[900], // vai juntar todas contas atй o 100, precisa aumentar ou diminuir se for preciso.
        
count
    
;
    for(new 
0100i++){
        
format(filesizeof(file), CONTASi);
        if(
DOF2::FileExists(string)){
            
format(string_2sizeof(string_2), "%d [%s]\n"iDOF2::GetString(file"Nome"));
            
strcat(string_3string_2);
            
count++; // vai ser incrementado caso exista.
        
}
    }
    
printf("%d"strlen(string_3)); // se der 899 й pq nгo cabem mais e precisa aumentar...
    
if(!count){
        return 
SendClientMessage(playerid, -1"Nenhuma Key foi encontrada!");
    }else{
        
ShowPlayerDialog(playeridDIALOGNORESPONSEDIALOG_STYLE_MSGBOX"Keys existentes"string_3"Ok""");
    }
    return 
1;

Vou ter que fazer gambiarra mesmo porque eu preciso que o nome do arquivo seja a prуpria key :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)