Mysql Threaded Question - 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: Mysql Threaded Question (
/showthread.php?tid=444713)
Mysql Threaded Question -
Abreezy - 17.06.2013
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.
Re: Mysql Threaded Question -
Enforcer501 - 18.06.2013
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.
Re: Mysql Threaded Question -
Abreezy - 18.06.2013
I tried with 0 as well and it didn't work, hm, I'll try again, thanks.
Re: Mysql Threaded Question -
Abreezy - 18.06.2013
Hey guys, I tried with the 0 and it still shows up at balance of "1". Is there something else i'm doing wrong?
Re: Mysql Threaded Question -
Vince - 18.06.2013
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.
Re: Mysql Threaded Question -
Abreezy - 18.06.2013
Hm, so you cant use it for other commands like that at all?