SA-MP Forums Archive
PVar 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: PVar not saving (/showthread.php?tid=379169)



PVar not saving - jameskmonger - 20.09.2012

I'm trying to save a PVar but it just won't work. Here is my SQL method:
pawn Код:
forward CheckCharExists_handle(playerid);
public CheckCharExists_handle(playerid) {
    new rows, fields;
    cache_get_data(rows, fields);
    printf("r: %d", rows);
    if(rows > 0) {
        SetPVarInt(playerid, "CharFound", 1);
    } else {
        SetPVarInt(playerid, "CharFound", 0);
    }
    printf("cf: %d", GetPVarInt(playerid, "CharFound"));
}

CheckCharExists(playerid, char_name[])
{
    new string[128];
    CheckMySQL();
    format(string, sizeof(string), "SELECT * FROM characters WHERE Name='%s'", char_name);
    mysql_function_query(dbHandle, string, true, "CheckCharExists_handle", "i", playerid);
}
As you can see, it sets the PVar depending on if there are any rows. "cf" and "r" are both printed in the console, and both say "1". I call the CheckCharExists method, and then after that I call the RegisterPlayer method, but I have this in RegisterPlayer:
pawn Код:
if(GetPVarInt(playerid, "CharFound") == 1) {
        return SendClientMessage(playerid, COLOR_GREY, "That character name is already registered."),
               ShowPlayerDialog(playerid, REGISTER_CHARACTER_DIALOG, DIALOG_STYLE_INPUT, "Character Name", "Please enter your desired character name below.", "Register", ""),
               1;
    }
And that message is not printed! I'd appreciate any help


Re: PVar not saving - jameskmonger - 20.09.2012

Alright, i'll add a lot of debugging lines I used a normal variable and got the same problem, though.


Re: PVar not saving - jameskmonger - 20.09.2012

Alright, i'll add a lot of debugging lines I used a normal variable and got the same problem, though.


Re: PVar not saving - jameskmonger - 21.09.2012

The pvar was saving, but the query was not completing until after the check and so it would equal 0 when checked and would only be set afterwards :P