Switch, cases & returns. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Switch, cases & returns. (
/showthread.php?tid=155248)
Switch, cases & returns. -
Carlton - 17.06.2010
Hey, this codes' been bugging me for a bit now. Here's a little detail: My business system needs products for items to be bought, now, so the business i'm buying from has 0 products, OK, but i'm still able to buy the item, it says:
Quote:
Originally Posted by Text
[Error]: This store has no products
|
but then it still shows the menu of what item i'd like to buy. Can someone check this out..
pawn Код:
command(buy, playerid, params[]) {
new stringformat[128];
for(new i = 0; i < TOTAL_BUSINESSES; i ++ ) {
if(IsPlayerInRangeOfPoint(playerid, 55.0, BizData[i][bExPos][0],BizData[i][bExPos][1],BizData[i][bExPos][2])) {
if(BizData[i][bProducts] < 1) return SendClientMessage(playerid, COLOR_SYSTEM, "[Error]: This store has no products.");
switch(BizData[i][bType]) {
case 0: {
// The rest of the code doesn't need to be shown, but you get the process, it goes to the cases even thought I returned the message and the products are 0
I tried using return 0 and ignoring the message and return 1, but the same effect.
Re: Switch, cases & returns. -
Mike_Peterson - 17.06.2010
I am not totally sure but if(BizData[i][bProducts] < 1) doesnt this mean the shop has products? and the next line is
return SendClientMessage(playerid, COLOR_SYSTEM, "[Error]: This store has no products.");
Im not very experienced but doesnt this mean even if there are items it still says the error?
try doing: if(BizData[i][bProducts] < 0) try this and check if this helps.
If this helps im very glad to help you, coz i learned something then too.
Re: Switch, cases & returns. -
NewTorran - 17.06.2010
Quote:
Originally Posted by PhonicStudios
I am not totally sure but if(BizData[i][bProducts] < 1) doesnt this mean the shop has products? and the next line is
return SendClientMessage(playerid, COLOR_SYSTEM, "[Error]: This store has no products.");
Im not very experienced but doesnt this mean even if there are items it still says the error?
try doing: if(BizData[i][bProducts] < 0) try this and check if this helps.
If this helps im very glad to help you, coz i learned something then too.
|
< 1 - is checking if the biz has 0 products or below,
< 0 - however is checking if the biz has -1 products or below
Re: Switch, cases & returns. -
Carlton - 17.06.2010
Quote:
Originally Posted by PhonicStudios
I am not totally sure but if(BizData[i][bProducts] < 1) doesnt this mean the shop has products? and the next line is
return SendClientMessage(playerid, COLOR_SYSTEM, "[Error]: This store has no products.");
Im not very experienced but doesnt this mean even if there are items it still says the error?
try doing: if(BizData[i][bProducts] < 0) try this and check if this helps.
If this helps im very glad to help you, coz i learned something then too.
|
Incorrect, read your statement in words not in a coding language.
" If the Business Products is less than 0 ", why would I check if a business's products are not even 0, I never heard of something with a negative amount of products.