Always 100 - 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: Always 100 (
/showthread.php?tid=459547)
Always 100 -
thefatshizms - 23.08.2013
pawn Код:
new payment = (weight > 9 && weight <= 50) ? 100 : (weight > 50 && weight <= 100) ? 150 : (weight > 100 && weight <= 150) ? 200 : (weight > 150 && weight <= 200) ? 250 : 0;
Payment is always 100, even if weight is above 50..
Re: Always 100 -
thefatshizms - 23.08.2013
I've read this
http://www.swansontec.com/sopc.html
And if I understand correctly, it 'reads' from right to left? I tried this to test it:
pawn Код:
new payment = (9 < weight && 50 => weight) ? 100 : (50 < weight && 100 => weight) ? 150 : (100 < weight && 150 => weight) ? 200 : (150 < weight && 200 => weight) ? 250 : 0;
But got errors.
I've also tried
pawn Код:
new payment = (weight > 9 && weight <= 50) ? 100 : ((weight > 50 && weight <= 100) ? 150 : ((weight > 100 && weight <= 150) ? 200 : ((weight > 150 && weight <= 200) ? 250 : 0)));
But the same result.
Re: Always 100 -
Konstantinos - 23.08.2013
Have you tried?
pawn Код:
new
payment
;
if( weight > 9 && weight <= 50 ) payment = 100;
else if( weight > 50 && weight <= 100 ) payment = 150;
else if( weight > 100 && weight <= 150 ) payment = 200;
else if( weight > 150 && weight <= 200 ) payment = 250;
else payment = 0;
// -- OR --
new
payment
;
switch( weight )
{
case 10 .. 50: payment = 100;
case 51 .. 100: payment = 150;
case 101 .. 150: payment = 200;
case 151 .. 200: payment = 250;
default: payment = 0;
}
Re: Always 100 -
thefatshizms - 23.08.2013
Quote:
Originally Posted by Konstantinos
Have you tried?
pawn Код:
new payment ; if( weight > 9 && weight <= 50 ) payment = 100; else if( weight > 50 && weight <= 100 ) payment = 150; else if( weight > 100 && weight <= 150 ) payment = 200; else if( weight > 150 && weight <= 200 ) payment = 250; else payment = 0;
// -- OR --
new payment ; switch( weight ) { case 10 .. 50: payment = 100; case 51 .. 100: payment = 150; case 101 .. 150: payment = 200; case 151 .. 200: payment = 250; default: payment = 0; }
|
I know how to do it that way. I've never used the ternary operator with nesting.. So I thought i'd try it.
Re: Always 100 -
thefatshizms - 23.08.2013
Yes, but within the language guide it says exactly the same.
Source:
http://puu.sh/48ZD6.png
Re: Always 100 -
Konstantinos - 23.08.2013
Quote:
Originally Posted by thefatshizms
I know how to do it that way. I've never used the ternary operator with nesting.. So I thought i'd try it.
|
The reason I posted the above is not because I doubt if you knew it or not. Does it actually work without the ternary operator method?
Re: Always 100 -
thefatshizms - 23.08.2013
Quote:
Originally Posted by Konstantinos
The reason I posted the above is not because I doubt if you knew it or not. Does it actually work without the ternary operator method?
|
Ah that's probably the problem, ahah. It doesn't work without the ternary (Still 100).
edit: Fixed! It was a stupid mistake..