if statement fail / bug - 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: if statement fail / bug (
/showthread.php?tid=234960)
if statement fail / bug -
DaneAMattie - 04.03.2011
Hello people,
I have 2 floats (Oz and TheZ[playerid])
and i tested it with send client message Oz = 402.1 and TheZ[playerid] = 52.03
now i have this:
Код:
if(Oz <= theZ[playerid])
{
SendClientMessage(playerid,COLOR_RED,"Oz is smaller then theZ]");
}
and i get the message, but how is Oz smaller then TheZ if TheZ is only 52 and Oz is 402
Re: if statement fail / bug -
Backwardsman97 - 04.03.2011
I would debug it more. Sometimes there's something weird but it's hard to tell without more of your code. How are you setting these floats?
pawn Код:
Oz = 5.0;
theZ[playerid] = 2.0;
printf("Oz:%f - theZ:%f",Oz,theZ[playerid]);
if(Oz > theZ[playerid])
print("Oz is bigger");
else
print("theZ is bigger");
Re: if statement fail / bug -
DaneAMattie - 04.03.2011
Quote:
Originally Posted by Backwardsman97
I would debug it more. Sometimes there's something weird but it's hard to tell without more of your code. How are you setting these floats?
pawn Код:
Oz = 5.0; theZ[playerid] = 2.0; printf("Oz:%f - theZ:%f",Oz,theZ[playerid]);
if(Oz > theZ[playerid]) print("Oz is bigger"); else print("theZ is bigger");
|
i tried your code and it seems if statement just fails XD
Re: if statement fail / bug -
GaGlets(R) - 04.03.2011
I just lolled..
Make sure they are defined as floats
new Float: ... ;
And make sure you have no warning messages when compiling.
pawn Код:
new Float:Oz = 5.0;
new Float:theZ[playerid] = 2.0;
printf("Oz:%f - theZ:%f",Oz,theZ[playerid]);
if(Oz > theZ[playerid]) {
print("Oz is bigger"); }
else {
print("theZ is bigger"); }
Re: if statement fail / bug -
Backwardsman97 - 04.03.2011
You forgot to define them as floats yourself lol. You could also try Floatcmp.
Edit:I see you corrected it.
pawn Код:
Oz = 5.0;
theZ[playerid] = 2.0;
switch(floatcmp(Oz,theZ[playerid]))
{
case -1:print("theZ is bigger.");
case 1:print("Oz is bigger");
default:print("They are the same....");
}
Re: if statement fail / bug -
DaneAMattie - 04.03.2011
Quote:
Originally Posted by GaGlets®
I just lolled..
Make sure they are defined as floats
new Float: ... ;
And make sure you have no warning messages when compiling.
pawn Код:
new Float:Oz = 5.0; new Float:theZ[playerid] = 2.0; printf("Oz:%f - theZ:%f",Oz,theZ[playerid]);
if(Oz > theZ[playerid]) { print("Oz is bigger"); } else { print("theZ is bigger"); }
|
i defined as float and i have no warnings
Re: if statement fail / bug -
DaneAMattie - 04.03.2011
Quote:
Originally Posted by Backwardsman97
You forgot to define them as floats yourself lol. You could also try Floatcmp.
Edit:I see you corrected it.
pawn Код:
Oz = 5.0; theZ[playerid] = 2.0; switch(floatcmp(Oz,theZ[playerid])) { case -1:print("theZ is bigger."); case 1:print("Oz is bigger"); default:print("They are the same...."); }
|
i tried it and same result, it sais theZ is bigger XD