Mysql Threaded Question
#1

I have this code, but It doesn't work. I'm trying to still learn these new functions before I convert my gamemode. Anyone tell me if I'm doing something wrong, thanks in advance.

pawn Код:
public BankAccBal(account) {

    new bal, bals[64];

    format(myquery, sizeof(myquery), "SELECT balance FROM saes_bank_accounts WHERE number='%i'", account);
    mysql_function_query(1, myquery, true, "OnBankBal", "d", account);
    return 1;
   
}

forward OnBankBal(account);
public OnBankBal(account)
{
    new rows, fields;
    cache_get_data(rows, fields);
    new temp[64];
    new bal;
    cache_get_field_content(1, "balance", temp);
    bal = strval(temp);
    return bal;
}


CMD:getbalance(playerid, params[])
{
    new num, balance;
    if(sscanf(params, "d", num)) return SendClientMessage(playerid, -1, "> /getbalance accountnumber");
   
    balance = BankAccBal(num);
   
    format(msgstring, sizeof(msgstring), "Bank account %d has %d dollars in it.", num, balance);
    SendClientMessage(playerid, -1, msgstring);
   
    return 1;
}
It always says: Bank account numberhere has 1 dollars in it. It always say 1 dollar, so not sure what i'm doing wrong.
Reply
#2

cache_get_field_content(1, "balance", temp);

This should be 0 - remember you count starting from 0 up.

You're trying to fetch from a row that was likely never returned, assuming it returned only 1 row.
Reply
#3

I tried with 0 as well and it didn't work, hm, I'll try again, thanks.
Reply
#4

Hey guys, I tried with the 0 and it still shows up at balance of "1". Is there something else i'm doing wrong?
Reply
#5

You can't do something like this with threading. It's just plain impossible. Everything that relies on the result of the query has to be moved into public OnBankBal.
Reply
#6

Hm, so you cant use it for other commands like that at all?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)