if statement fail / bug
#1

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
Reply
#2

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");
Reply
#3

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
Reply
#4

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"); }
Reply
#5

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....");
}
Reply
#6

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
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)