Y_Ini - Reading string (i tried..)
#1

So.. it's saving:

pawn Код:
format(OnlineTime, sizeof(OnlineTime), "%02d:%02d:%02d", PlayerInfo[playerid][pOnlineHours], PlayerInfo[playerid][pOnlineMinutes], PlayerInfo[playerid][pOnlineSeconds]);

INI_WriteString(Account,        "Online_Time",      OnlineTime);
And now to load.. i tried with format, strval(value), strlen(value) and other options..

pawn Код:
if(!strcmp(name, "Online_Time"))
{
        PlayerInfo[playerid][pOnlineHours]      = strval(value);
        PlayerInfo[playerid][pOnlineMinutes]    = strval(value);
        PlayerInfo[playerid][pOnlineSeconds]    = strval(value);
}
But i dunno what to do to read it.. oh.. and i tried with INI_String.. no results.
Reply
#2

Quote:
pawn Код:
if(!strcmp(name, "Online_Time"))
{
        PlayerInfo[playerid][pOnlineHours]      = strval(value);
        PlayerInfo[playerid][pOnlineMinutes]    = strval(value);
        PlayerInfo[playerid][pOnlineSeconds]    = strval(value);
}
But i dunno what to do to read it.. oh.. and i tried with INI_String.. no results.

Your current code ain't gonna do it...
Show your attempts of INI_String.
Reply
#3

Hi, try this:

(I guess 'value' is the string name)
pawn Код:
if(!strcmp(name, "Online_Time"))
{
    new tmpx[20], which;
    for(new i=0; i<strlen(value); i++)
    {
        if(value[i] == ':')
        {
            if(which == 0) PlayerInfo[playerid][pOnlineHours] = strval(tmpx);
            if(which == 1) PlayerInfo[playerid][pOnlineMinutes] = strval(tmpx);
            format(tmpx, sizeof(tmpx), "");
            which++;
        }
        else format(tmpx, sizeof(tmpx), "%s%c", tmpx, value[i]);
    }
    PlayerInfo[playerid][pOnlineSeconds] = strval(tmpx);
}
I hope this works, let me know if there are any problems.

Jeffry
Reply
#4

Works. To lock.
Reply
#5

There's no need to write such a complex loader for something like this alone. There's a much much more complex unformatting function for that... sscanf 2.0.

This would be very simple:
pawn Код:
sscanf(value, "p<:>ddd", PlayerInfo[playerid][pOnlineHours], PlayerInfo[playerid][pOnlineMinutes], PlayerInfo[playerid][pOnlineSeconds]);
Edit
To save some memory, you could make pOnlineMinutes and pOnlineSeconds char arrays. This reduces the size by half and would be usable since minutes and seconds never go near 255.
pawn Код:
new pOnlineHours[MAX_PLAYERS], pOnlineMinutes[MAX_PLAYERS char], pOnlineSeconds[MAX_PLAYERS char];
// In your 1-second loop...
pOnlineSeconds{playerid} ++;
if(pOnlineSeconds{playerid} == 60)
{
    pOnlineSeconds{playerid} = 0, pOnlineMinutes{playerid} ++;
    if(pOnlineMinutes{playerid} == 60)
    {
        pOnlineMinutes{playerid} = 0, pOnlineHours[playerid] ++;
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)