warning 209: returning values -
biker122 - 14.04.2016
Hey guys, I've ran through a small problem. Since it's been a long time I scripted - I'm not able to solve this simple shit easily. I've made a function to fetch a value from a database (MySQL).
pawn Код:
function FetchBankAccountByName(name[24])
{
mysql_format(MySQL, gQuery, 256, "SELECT * FROM `"Banks_Table"` WHERE `Holder` = '%e'", name);
mysql_tquery(MySQL, gQuery, "Safe_FetchBankAccountByName", "i");
}
function Safe_FetchBankAccountByName(Balance)
{
new rows, fields;
cache_get_data(rows, fields);
if(rows)
{
Balance = cache_get_field_content_int(0, "Balance", MySQL);
}
return Balance;
}
and this is where I'm using it:
pawn Код:
if(!IsPlayerConnected(GetPlayerID(Bank_Transfer_To[playerid])))
mysql_format(MySQL, str, sizeof str, "UPDATE `"Banks_Table"` SET `Balance` = '%i' WHERE `Holder` = '%e'", FetchBankAccountByName(Bank_Transfer_To[playerid]) + value, Bank_Transfer_To[playerid]);
mysql_tquery(MySQL, str, "", "");
}
Help me finish this piece of code, guys.
Thanks!
Re: warning 209: returning values -
Konstantinos - 14.04.2016
No need of all that, just:
pawn Код:
mysql_format(MySQL, str, sizeof str, "UPDATE "Banks_Table" SET Balance=Balance + %i WHERE Holder='%e'", value, Bank_Transfer_To[playerid]);
Re: warning 209: returning values -
biker122 - 14.04.2016
Thanks for the easy step, and I also have the same warning at a different place.
pawn Код:
function IsBankHolder(name[24])
{
mysql_format(MySQL, gQuery, 128, "SELECT * FROM `"Banks_Table"` WHERE `Holder` = '%e'", name);
mysql_tquery(MySQL, gQuery, "Safe_IsBankHolder", "");
}
function Safe_IsBankHolder()
{
new rows, fields;
cache_get_data(rows, fields);
return rows;
}
This is being used at:
pawn Код:
if(!IsBankHolder(username))
{
SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"The specified USERNAME doesn't own a bank account!");
return 1;
}
Re: warning 209: returning values -
Konstantinos - 14.04.2016
IsBankHolder does not return any value but other than that, public functions are not meant to be used for that.
One way to achieve that is by adding the rest of the code in the public function Safe_IsBankHolder along with the error message.
Also another tip is to use COUNT instead of selecting everything from a table in order to check if there are rows or not. Then retrieving from 0 row and 0 field to get the rows.
Re: warning 209: returning values -
biker122 - 14.04.2016
I've tried something different, so please let me know if the code written below will work or not:
pawn Код:
// Inside the command
if(!IsUserOnline(username))
{
mysql_format(MySQL, gQuery, 256, "SELECT * FROM `"Banks_Table"` WHERE `Holder` = '%e'", username);
mysql_tquery(MySQL, gQuery, "Safe_IsBankHolder", "i", playerid);
return 1;
}
pawn Код:
function Safe_IsBankHolder(playerid)
{
new rows, fields, str[128];
cache_get_data(rows, fields);
if(rows)
{
format(str, sizeof str, ""STEELBLUE"You're now transferring funds to "RED"%s"STEELBLUE". Please enter a amount to transfer:", Bank_Transfer_To[playerid]);
ShowPlayerDialog(playerid, BANK_MENU_2_1, DIALOG_STYLE_INPUT, ""RED"Bank - Transfer Funds", str, "Transfer", "Cancel");
}
else
{
SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"The specified USERNAME doesn't own a bank account!");
}
return 1;
}
Re: warning 209: returning values -
Konstantinos - 14.04.2016
The code is correct. About the suggestion I told you about, replace with:
pawn Код:
"SELECT COUNT(*) FROM `"Banks_Table"` WHERE `Holder` = '%e'"
and in Safe_IsBankHolder:
pawn Код:
if (cache_get_row_int(0, 0, MySQL)) // if retrieved rows is not 0
{
// format and ShowPlayerDialog
}
else SendClientMessage(playerid, -1, ""RED"ERROR: "GREY"The specified USERNAME doesn't own a bank account!");
Re: warning 209: returning values -
biker122 - 14.04.2016
So according to your code, should I just execute IsBankHolder function in the command? So it takes care of the remaining code
Re: warning 209: returning values -
Konstantinos - 14.04.2016
IsBankHolder only executes the query and since it does not return any value directly, I personally see no use of it. Just execute the query in the command like in your previous post.
Re: warning 209: returning values -
biker122 - 14.04.2016
Alright, now I understand it better. Thanks!