SA-MP Forums Archive
Services not saving - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Services not saving (/showthread.php?tid=281294)



Services not saving - Luis- - 05.09.2011

Alright, well they are loading perfectly fine but they don't seem to be saving to the variables within the enum.
pawn Код:
enum sInfo
{
    sType,
    sFunds,
    sName[128],
}
new ServiceInfo[MAX_SERVICES][sInfo];
I have got the funds to save to the variable so they display perfectly well.

Although the type & name don't want to save, here are my codes.
pawn Код:
forward LoadServices();
public LoadServices()
{
    new
        line[512],
        placeholder
    ;
    mysql_query("SELECT * FROM services LIMIT " #MAX_SERVICES "");
    mysql_store_result();
    while(mysql_fetch_row_format(line))
    {
        new data[3];
        sscanf(line, "p<|>ddds[128]", placeholder, data[0], data[1], data[2]);
        print(line);
        ServiceInfo[services][sFunds] = data[0];
        ServiceInfo[services][sType] = data[1];
        ServiceInfo[services][sName] = data[2];
        services++;
        printf("DEBUG: %i Services Loaded.", services);
    }
    mysql_free_result();
}
I have been trying to get this working most of this morning and last night but still haven't got it to work correctly. Here are the logs.

Код:
[11:08:24] 1|150001|TESTING
[11:08:24] DEBUG: 1 Services Loaded.
As you can see they are loading correctly.

But when I do a debug command.
Код:
[11:08:35] SERVICES: , 0, $150001.
Which is very confusing.


Re: Services not saving - The_Moddler - 05.09.2011

What's your debug command, can you show it?


Re: Services not saving - Luis- - 05.09.2011

Yes.
pawn Код:
CMD:si(playerid, params[])
{
    for(new i=0; i<services; i++)
    {
        new str[256];
        format(str, sizeof(str), "SERVICES: %s, %d, $%d.", ServiceInfo[i][sName], ServiceInfo[i][sType], ServiceInfo[i][sFunds]);
        SendClientMessage(playerid, COLOR_RED, str);
        print(str);
    }
    return 1;
}



Re: Services not saving - Cyanide - 05.09.2011

The variable sName is a array, and you're setting the data as if it was a integer.

pawn Код:
stock LoadServices()
{
    new
        line[512],
        placeholder
    ;
    mysql_query("SELECT * FROM services LIMIT " #MAX_SERVICES "");
    mysql_store_result();
    while(mysql_fetch_row_format(line))
    {
        new data[3], sdata[ 128 ];
        sscanf(line, "p<|>ddds[128]", placeholder, data[0], data[1], sdata);
        print(line);
        ServiceInfo[services][sFunds] = data[0];
        ServiceInfo[services][sType] = data[1];
        strcat( ServiceInfo[services][sName], sdata );
        services++;
        printf("DEBUG: %i Services Loaded.", services);
    }
    mysql_free_result();
}



Re: Services not saving - Luis- - 05.09.2011

That still isn't doing anything.


Re: Services not saving - Cyanide - 05.09.2011

I also noticed that your debugging code that printed the variable line is only loading three parameters, but you have four specifiers in sscanf.


Re: Services not saving - Luis- - 05.09.2011

The first parameter is a placeholder.


Re: Services not saving - Cyanide - 05.09.2011

Quote:
Originally Posted by -Luis
Посмотреть сообщение
The first parameter is a placeholder.
The placeholder would also print if the SQL field actually existed. That's the reason why it isn't properly loading. Try this:

pawn Код:
sscanf(line, "p<|>dds[128]", data[0], data[1], sdata);



Re: Services not saving - Luis- - 05.09.2011

Right now its just the name that isn't working, which is weird.


Re: Services not saving - Luis- - 05.09.2011

Ah, fixed. you forgot to add "sizeof(sdata)". Thanks.