[Solved] Dini does not write to file. -
DesertFoxNight - 09.05.2011
I'm having a difficult time trying to write and read from a file. I've created two commands in my Gamemode: one to record the Name, IP, and Score of a player; and the other one to retrieve the Name and Score of the person. The code looks like this:
pawn Код:
COMMAND:pass(playerid){
new file[250] = "/userfiles/testing.ini";
GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
GetPlayerIp(playerid, PlayerInfo[playerid][pIP], 16);
PlayerInfo[playerid][pScore] = GetPlayerScore(playerid);
dini_Set( file, "Name", PlayerInfo[playerid][pName] );
dini_Set( file, "IP", PlayerInfo[playerid][pIP]);
dini_IntSet( file, "Score", PlayerInfo[playerid][pScore] );
return 1;
}
COMMAND:get(playerid){
new file[250] = "/userfiles/testing.ini";
new msg[150];
format( msg, sizeof(msg), "Name: %s", dini_Get(file, "Name") );
SendClientMessage( playerid, BLUE, msg );
format( msg,sizeof(msg),"Score: %d", dini_Int(file, "Score") );
SendClientMessage( playerid, BLUE, msg );
return 1;
}
I've tried different combination for the file name such as:
- C:\Users\Owner\Desktop\Games\GTA SA\Server\userfiles\testing.ini
- C:\\Users\\Owner\\Desktop\\Games\\GTA SA\\Server\\userfiles\\testing.ini
- C:/Users/Owner/Desktop/Games/GTA SA/Server/userfiles/testing.ini
- \\userfiles\\testing.ini
- /userfiles/testing.ini
- userfiles\testing.ini
- userfiles/testing.ini
Even so, dini_IntSet does not write to the directory where I have the
testing.ini file that I manually created in
userfiles. I'm running Windows Vista on my computer, so I also tried running my server in Administrator mod, but even that doesn't help. I've done File I/O in the the past (C, Python, and PHP), but this time around I can't figure out why dini isn't working for me. I know that there are better File I/O for Pawno, but right now I'm focusing on dini since I finally figured out how to use it by going over the source code.
Thank you for your time.
Re: Dini does not write to file. -
Biesmen - 09.05.2011
Why are you defining file in this case?
Try it without defining file, so we can make a diagnosis.
pawn Код:
COMMAND:pass(playerid){
GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
GetPlayerIp(playerid, PlayerInfo[playerid][pIP], 16);
PlayerInfo[playerid][pScore] = GetPlayerScore(playerid);
dini_Set( "/userfiles/testing.ini", "Name", PlayerInfo[playerid][pName] );
dini_Set( "/userfiles/testing.ini", "IP", PlayerInfo[playerid][pIP]);
dini_IntSet( "/userfiles/testing.ini", "Score", PlayerInfo[playerid][pScore] );
return 1;
}
COMMAND:get(playerid){
new msg[150];
format( msg, sizeof(msg), "Name: %s", dini_Get("/userfiles/testing.ini", "Name") );
SendClientMessage( playerid, BLUE, msg );
format( msg,sizeof(msg),"Score: %d", dini_Int("/userfiles/testing.ini", "Score") );
SendClientMessage( playerid, BLUE, msg );
return 1;
}
Re: Dini does not write to file. -
DesertFoxNight - 09.05.2011
I wanted to test to see how dini worked because I tried to do the raw File I/O such as fopen, fread, fwrite, etc. but it crashed my server. I'm used to defining the directory to a local variable because that's what I've done in C, Phyton, and PHP with File I/O. I'll give it a try defining the directory this time instead of defining it locally in the command and report back if it works.
Re: Dini does not write to file. -
DesertFoxNight - 09.05.2011
I finally got it to work. It turned out when I used this define:
"%s.ini", dini wrote the file in
Server\scriptfiles and not to the directory where
samp-server is located. Like I said earlier, I do have experience with File I/O in other languages so I naturally assumed the root directory was
Server not
scriptfiles because samp-server is located in the folder
Server. So thank you for your help and time I really appreciated.