redundant test: constant expression is non-zero
#1

I have the error:
Код:
(10531) : warning 206: redundant test: constant expression is non-zero
Код:
stock IsAMotorcycle(carid)
{
	if(carid == 586, 581, 523, 522, 521, 471, 468, 463, 462, 461, 448) return 1;
	return 0;
}
Код:
Line 10531 == if(carid == 586, 581, 523, 522, 521, 471, 468, 463, 462, 461, 448) return 1;
Reply
#2

You cannot compare like that. You would've to check if the carid is N everytime BUT.. switch is faster:
pawn Код:
stock IsAMotorcycle(carid)
{
    switch (carid)
    {
        case 448, 461 .. 463, 468, 471, 521 .. 523, 581, 586: return 1;
    }
    return 0;
}
Make sure that when you use that function, you use GetVehicleModel.
pawn Код:
if (IsAMotorcycle(GetVehicleModel(vehicleid))) ...
Reply
#3

Why do you have the dots (..) between some of the numbers?
Reply
#4

Quote:
Originally Posted by Blademaster680
Посмотреть сообщение
Why do you have the dots (..) between some of the numbers?
.. works like, if you want numbers 1 to 10, you can simply do 1 .. 10
Reply
#5

Let's say you want to check if the carid is one of these:
pawn Код:
case 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410:
{
    // code..
}
Instead of writing all those numbers, you could just do:
pawn Код:
case 400 .. 410:
{
    // code..
}
and any number in between will be valid.
Reply
#6

Ahhh ok thanks, shortcut instead of typing them all out
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)