[Help] Returning "Null" -
ApolloScripter - 13.01.2019
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 i = 0; i < 500; i++)
{
format(TopSystem, sizeof(TopSystem), "ScoreTOP/%i.ini", i);
pNameInFile = DOF2_GetString(TopSystem, "Nome");
printf("%s", pNameInFile);
}
Re: [Help] Returning "Null" -
ApolloScripter - 13.01.2019
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.
Re: [Help] Returning "Null" -
codExpert - 13.01.2019
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_file, io_read))){
//loops through file rows
while(fread(handle, buf)){
strexplode(output, buf, "=");
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_file, io_append))){
fwrite(handle, s);
fclose(handle);
}
return 1;
}
//user score is in the file, so we have to select all rows
if((handle = fopen(player_scores_file, io_read))){
//loops through file rows
while(fread(handle, buf)){
strexplode(output, buf, "=");
//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_file, io_write))){
//adds rows into file
for(new i; i < rowCnter; i++){
fwrite(handle, fileRows[i]);
}
fclose(handle);
}
return true;
}
Re: [Help] Returning "Null" -
ApolloScripter - 13.01.2019
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_file, io_read))){
//loops through file rows
while(fread(handle, buf)){
strexplode(output, buf, "=");
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_file, io_append))){
fwrite(handle, s);
fclose(handle);
}
return 1;
}
//user score is in the file, so we have to select all rows
if((handle = fopen(player_scores_file, io_read))){
//loops through file rows
while(fread(handle, buf)){
strexplode(output, buf, "=");
//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_file, io_write))){
//adds rows into file
for(new i; i < rowCnter; i++){
fwrite(handle, fileRows[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.
Re: [Help] Returning "Null" -
codExpert - 14.01.2019
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.
Re: [Help] Returning "Null" -
ApolloScripter - 14.01.2019
Does my problem have a solution in DOF?
Re: [Help] Returning "Null" -
codExpert - 14.01.2019
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.