Loading File
#1

Hi, all. What's wrong in this public:
Код:
public LoadPlayerPhone(playerid)
{
	new string[64];
	new playername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, playername, sizeof(playername));
	format(string, sizeof(string), "phone/%s.ini", playername);
	if(fexist(string))
	{
	    new File: hFile = fopen(string, io_read);
	    if (hFile)
		{
        	new key[256] , val[256];
 			new Data[256];
      		while (fread(hFile, Data, sizeof(Data)))
			{
				key = ini_GetKey(Data);
				if( strcmp( key , "Online" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobOnline] = strval( val ); }
  				if( strcmp( key , "Number" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNumber] = strval( val ); }
  				if( strcmp( key , "Note1" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote1], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note1s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote1s] = strval( val ); }
			    if( strcmp( key , "Note2" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote2], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note2s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote2s] = strval( val ); }
			    if( strcmp( key , "Note3" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote3], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note3s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote3s] = strval( val ); }
			    if( strcmp( key , "Note4" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote4], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note4s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote4s] = strval( val ); }
			    if( strcmp( key , "Note5" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote5], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note5s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote5s] = strval( val ); }
  				if( strcmp( key , "Note6" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote6], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note6s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote6s] = strval( val ); }
			    if( strcmp( key , "Note7" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote7], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note7s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote7s] = strval( val ); }
			    if( strcmp( key , "Note8" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote8], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note8s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote8s] = strval( val ); }
			    if( strcmp( key , "Note9" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote9], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note9s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote9s] = strval( val ); }
			    if( strcmp( key , "Note10" , true ) == 0 ) { val = ini_GetValue( Data ); strmid(MobileInfo[playerid][mobNote10], val, 0, strlen(val)-1, 255); }
			    if( strcmp( key , "Note10s" , true ) == 0 ) { val = ini_GetValue( Data ); MobileInfo[playerid][mobNote10s] = strval( val ); }
  				fclose(hFile);
  				return 1;
  			}
  		}
	}
	else
	{
	    new File: hFile = fopen(string, io_write);
		if (hFile)
		{
			new var[64];
			MobileInfo[playerid][mobNumber] = PlayerInfo[playerid][pPnumber];
			format(var, 64, "On‌line=%d\n", MobileInfo[playerid][mobOnline]);fwrite(hFile, var);
			format(var, 64, "Number=%d\n", MobileInfo[playerid][mobNumber]);fwrite(hFile, var);
			format(var, 64, "Note1=%s\n",MobileInfo[playerid][mobNote1]);fwrite(hFile, var);
			format(var, 64, "Note1s=%d\n",MobileInfo[playerid][mobNote1s]);fwrite(hFile, var);
			format(var, 64, "Note2=%s\n",MobileInfo[playerid][mobNote2]);fwrite(hFile, var);
			format(var, 64, "Note2s=%d\n",MobileInfo[playerid][mobNote2s]);fwrite(hFile, var);
			format(var, 64, "Note3=%s\n",MobileInfo[playerid][mobNote3]);fwrite(hFile, var);
			format(var, 64, "Note3s=%d\n",MobileInfo[playerid][mobNote3s]);fwrite(hFile, var);
			format(var, 64, "Note4=%s\n",MobileInfo[playerid][mobNote4]);fwrite(hFile, var);
			format(var, 64, "Note4s=%d\n",MobileInfo[playerid][mobNote4s]);fwrite(hFile, var);
			format(var, 64, "Note5=%s\n",MobileInfo[playerid][mobNote5]);fwrite(hFile, var);
			format(var, 64, "Note5s=%d\n",MobileInfo[playerid][mobNote5s]);fwrite(hFile, var);
			format(var, 64, "Note6=%s\n",MobileInfo[playerid][mobNote6]);fwrite(hFile, var);
			format(var, 64, "Note6s=%d\n",MobileInfo[playerid][mobNote6s]);fwrite(hFile, var);
			format(var, 64, "Note7=%s\n",MobileInfo[playerid][mobNote7]);fwrite(hFile, var);
			format(var, 64, "Note7s=%d\n",MobileInfo[playerid][mobNote7s]);fwrite(hFile, var);
			format(var, 64, "Note8=%s\n",MobileInfo[playerid][mobNote8]);fwrite(hFile, var);
			format(var, 64, "Note8s=%d\n",MobileInfo[playerid][mobNote8s]);fwrite(hFile, var);
			format(var, 64, "Note9=%s\n",MobileInfo[playerid][mobNote9]);fwrite(hFile, var);
			format(var, 64, "Note9s=%d\n",MobileInfo[playerid][mobNote9s]);fwrite(hFile, var);
			format(var, 64, "Note10=%s\n",MobileInfo[playerid][mobNote10]);fwrite(hFile, var);
			format(var, 64, "Note10s=%d\n",MobileInfo[playerid][mobNote10s]);fwrite(hFile, var);
			fclose(hFile);
			return 1;
		}
	}
	return 1;
}
If file doesn't exist it normally creates, but it doesn't load if it exist.
Reply
#2

fclose should come AFTER the while loop.
Reply
#3

Thanks a lot! Now works)
Didn't thought that it depends on it
Reply
#4

Everything depends on something in the world of scripting.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)