[Help] Returning "Null"
#1

Hello there, I created a list of files with a growing number, 1, 2, 3 ... within each file, the Score and the Player Name are saved, so I made a Loop through all files, and put it to print, returns "null" instead of returning the name in each file, has some logical error here, I believe, does anyone know what it is?

PHP код:
    new TopSystem[70];
    new 
pNameInFile[MAX_PLAYER_NAME];
    for(new 
0500i++)
    {
        
format(TopSystemsizeof(TopSystem), "ScoreTOP/%i.ini"i);
        
pNameInFile DOF2_GetString(TopSystem"Nome");
        
printf("%s"pNameInFile);
    } 
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
Well you spelt `name` wrong...
No... haha, it's in portuguese, my native language.
I'm still having the same problem, keep returning null.
Reply
#3

why are you using oldest possible include for loading data from ini?
and maybe you should start using mysql instead, because ini file reading with big player cnts is slowest method possible.
in case you want to use ini system you could just save player scores into 1 file.
i wrote simple example for 1 file solution
PHP код:
//https://sampforum.blast.hk/showthread.php?tid=362764
#include <strlib>
#define player_scores_file "player_scores.txt"
getPlayerScore(userName[24]){
    
//variables
    
new File:handle,
        
buf[128],
        
output[2][24],
        
userScore=-1;
    
//checks file exsistance
    
if((handle fopen(player_scores_fileio_read))){
        
//loops through file rows
        
while(fread(handlebuf)){
            
strexplode(outputbuf"=");
            if(!
strcmp(output[0],userName)){
                
userScore=strval(output[1]);
                break;
            }
        }
        
fclose(handle);
    }
    return 
userScore;
}
bool:savePlayerScore(userName[24],userScore){
    
//user score is smaller then 0
    
if(userScore 0)return false;
    
//check if player score is in the file
    
new File:handle,
        
buf[128],
        
userScoreFile=getPlayerScore(userName),
        
s[80],
        
fileRows[500][60],
        
rowCnter;
    
format(s,80,"%s=%d\r\n",userName,userScore);
    
//user score isnt in the file, so we can append the file
    
if(userScoreFile==-1){
        if((
handle fopen(player_scores_fileio_append))){
            
fwrite(handles);
            
fclose(handle);
        }
        return 
1;
    }
    
//user score is in the file, so we have to select all rows
    
if((handle fopen(player_scores_fileio_read))){
        
//loops through file rows
        
while(fread(handlebuf)){
            
strexplode(outputbuf"=");
            
//takes other players scores
            
if(strcmp(output[0],userName)!=0){
                
fileRows[rowCnter++]=buf;
            }
        }
        
fclose(handle);
    }
    
//adds extra row with new score
    
strmid(fileRows[rowCnter++],s,0,80,80);
    
//adds rows into file
    
if((handle fopen(player_scores_fileio_write))){
        
//adds rows into file
        
for(new irowCnteri++){
            
fwrite(handlefileRows[i]);
        }
        
fclose(handle);
    }
    return 
true;

Reply
#4

Quote:
Originally Posted by codExpert
Посмотреть сообщение
why are you using oldest possible include for loading data from ini?
and maybe you should start using mysql instead, because ini file reading with big player cnts is slowest method possible.
in case you want to use ini system you could just save player scores into 1 file.
i wrote simple example for 1 file solution
PHP код:
//https://sampforum.blast.hk/showthread.php?tid=362764
#include <strlib>
#define player_scores_file "player_scores.txt"
getPlayerScore(userName[24]){
    
//variables
    
new File:handle,
        
buf[128],
        
output[2][24],
        
userScore=-1;
    
//checks file exsistance
    
if((handle fopen(player_scores_fileio_read))){
        
//loops through file rows
        
while(fread(handlebuf)){
            
strexplode(outputbuf"=");
            if(!
strcmp(output[0],userName)){
                
userScore=strval(output[1]);
                break;
            }
        }
        
fclose(handle);
    }
    return 
userScore;
}
bool:savePlayerScore(userName[24],userScore){
    
//user score is smaller then 0
    
if(userScore 0)return false;
    
//check if player score is in the file
    
new File:handle,
        
buf[128],
        
userScoreFile=getPlayerScore(userName),
        
s[80],
        
fileRows[500][60],
        
rowCnter;
    
format(s,80,"%s=%d\r\n",userName,userScore);
    
//user score isnt in the file, so we can append the file
    
if(userScoreFile==-1){
        if((
handle fopen(player_scores_fileio_append))){
            
fwrite(handles);
            
fclose(handle);
        }
        return 
1;
    }
    
//user score is in the file, so we have to select all rows
    
if((handle fopen(player_scores_fileio_read))){
        
//loops through file rows
        
while(fread(handlebuf)){
            
strexplode(outputbuf"=");
            
//takes other players scores
            
if(strcmp(output[0],userName)!=0){
                
fileRows[rowCnter++]=buf;
            }
        }
        
fclose(handle);
    }
    
//adds extra row with new score
    
strmid(fileRows[rowCnter++],s,0,80,80);
    
//adds rows into file
    
if((handle fopen(player_scores_fileio_write))){
        
//adds rows into file
        
for(new irowCnteri++){
            
fwrite(handlefileRows[i]);
        }
        
fclose(handle);
    }
    return 
true;

Oh, I did not know of the existence of this include, I used DOF because it was what I had learned, I'll take a look, thanks for the help.

But I really want to know why the variable returns null, I want to know what is wrong in the code.
Reply
#5

it isn't worse one, its with decent speed, of course it can be written better and include could be used.
and again i say that .ini file handling is always the slowest method possible, even with the most optimized code.
Reply
#6

Does my problem have a solution in DOF?
Reply
#7

could you give link for DOF2 documentation, it can't be fixed without knowing include working mechanics.
and if it doesn't have documentation, then you should switch to something else for example.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)