Weird y_ini reading problem
#1

I'm making some position saving system(a filterscript), in which a player can save multiple positions and teleport back to them.
Well, they are saving fine in the files, and if I quit the server and come back, the file is also loaded and I can teleport to my saved positions.
The problem is - if I close the server(After I quit), and re-open it, the file can no longer be read. The file hasn't changed, but the server doesn't read it and I can't teleport to the positions I've saved.
What could this be all about?

Saving the position:
pawn Код:
new INI:File = INI_Open(PlayerPath(playerid));
            INI_SetTag(File, "data");
            format(str_tmp, sizeof(str_tmp), "X_%d", tmp2[playerid]);
            INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][0]);
            format(str_tmp, sizeof(str_tmp), "Y_%d", tmp2[playerid]);
            INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][1]);
            format(str_tmp, sizeof(str_tmp), "Z_%d", tmp2[playerid]);
            INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][2]);
            format(str_tmp, sizeof(str_tmp), "A_%d", tmp2[playerid]);
            INI_WriteFloat(File, str_tmp, pos_ACTUAL[playerid][tmp2[playerid]][3]);
            format(str_tmp, sizeof(str_tmp), "Counter_%d", tmp2[playerid]);
            INI_WriteInt(File, str_tmp, pos_COUNTER[playerid]);
            format(str_tmp, sizeof(str_tmp), "Interior_%d", tmp2[playerid]);
            INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
            format(str_tmp, sizeof(str_tmp), "VirtualWorld_%d", tmp2[playerid]);
            INI_WriteInt(File, str_tmp, pos_INT[playerid][tmp2[playerid]]);
            format(str_tmp, sizeof(str_tmp), "Name_%d", tmp2[playerid]);
            INI_WriteString(File, str_tmp, pos_NAME[playerid][tmp2[playerid]]);
            format(str_tmp, sizeof(str_tmp), "Handler_%d", tmp2[playerid]);
            INI_WriteInt(File, str_tmp, pos_Handler[playerid][tmp2[playerid]]);
            INI_Close(File);
            tmp2[playerid] = 0;
Reading:
pawn Код:
public LoadPlayerPos_data(playerid,name[],value[])
{
    new str_tmp[21];
    for(new i = 0; i < MAX_SAVED_POSITIONS_PER_PLAYER; i++)
    {
        format(str_tmp, sizeof(str_tmp), "X_%d", i);
        INI_Float(str_tmp, pos_ACTUAL[playerid][i][0]);
        format(str_tmp, sizeof(str_tmp), "Y_%d", i);
        INI_Float(str_tmp, pos_ACTUAL[playerid][i][1]);
        format(str_tmp, sizeof(str_tmp), "Z_%d", i);
        INI_Float(str_tmp, pos_ACTUAL[playerid][i][2]);
        format(str_tmp, sizeof(str_tmp), "A_%d", i);
        INI_Float(str_tmp, pos_ACTUAL[playerid][i][3]);
        format(str_tmp, sizeof(str_tmp), "Counter_%d", i);
        INI_Int(str_tmp, pos_COUNTER[playerid]);
        format(str_tmp, sizeof(str_tmp), "Interior_%d", i);
        INI_Int(str_tmp, pos_INT[playerid][i]);
        format(str_tmp, sizeof(str_tmp), "VirtualWorld_%d", i);
        INI_Int(str_tmp, pos_VW[playerid][i]);
        format(str_tmp, sizeof(str_tmp), "Name_%d", i);
        INI_String(str_tmp, pos_NAME[playerid][i], MAX_SAVE_POSITION_NAME_LENGTH);
        format(str_tmp, sizeof(str_tmp), "Handler_%d", i);
        INI_Int(str_tmp, pos_Handler[playerid][i]);
    }
    return 1;
}
Reply
#2

Show how LoadPlayerPos is being called.
Reply
#3

pawn Код:
public OnPlayerConnect(playerid)
{
    if(fexist(PlayerPath(playerid))) INI_ParseFile(PlayerPath(playerid), "LoadPlayerPos_%s", .bExtra = true, .extra = playerid);
    return 1;
}
Reply
#4

Are you storing the data in one or multiple files?
Reply
#5

Quote:
Originally Posted by Ada32
Посмотреть сообщение
Are you storing the data in one or multiple files?
One for each player.
Reply
#6

here you go, http://pastebin.com/3EaCt6f5

I couldn't get my head to work around any issues with why your code wouldn't work. I suspected it was the loop in LoadPlayerPos func, but you haven't posted anything on the arrays (pos_ACTUAL etc) so I went ahead with this.

currIndex is used to specify a position and it's information (handler, counter, pos_x etc) so you could increment and loop through all if you'd like. edit - with that being said, you basically use what you need as opposed storing all file information in arrays and then being selective.
Reply
#7

I don't see where total_saved_pos is getting any value, it's just... used?
EDIT: Just to prevent any furure misunderstandings... here is the whole code:
http://pastebin.com/X8YCxUqs
Reply
#8

Your code works as expected on my machine (even after I close and re-open the server) - so I don't know what is issue is on your end, sorry. It is however a very horrible concept. You create multiple multi-dimensional arrays to store ALL values from a user file. While this may work well on a simple user mode, when working with that much data it'd be best to handle the information you need as opposed to everything (or use an alternate saving method..)

Here's an unfinished, modified version of your code with a much better concept design if your interested. http://pastebin.com/y6CKVCQL. If you have any questions about that, feel free to PM me.
Reply
#9

Thanks for the optimization.
I've made some basic changes, and the file still isn't read after fsreload...
I have no idea how could this happen, as you said yourself it works for you, but for me it just... doesn't read the file after a restart. Your code does the same.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)