SA-MP Forums Archive
redundant test: constant expression is non-zero - 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: redundant test: constant expression is non-zero (/showthread.php?tid=475588)



redundant test: constant expression is non-zero - Jack_Leslie - 14.11.2013

pawn Код:
CMD:createhouse(playerid, params[])
{

    if(PlayerData[playerid][AdminLevel] < 5 ) return SendUnathorizedMessage(playerid);
   
    new interior, price, Float: X, Float: Y, Float: Z, Float: A, houseid = 999;
    if(sscanf(params, "ii", interior, price)) return SendClientMessage(playerid, C_SYNTAX, "Syntax:{FFFFFF} /createhouse [interior id] [price]");

    if(interior <= 0) return SendClientMessage(playerid, C_WHITE, "The interior ID must be above 0.");
    if(price < 50000) return SendClientMessage(playerid, C_WHITE, "A minimum house value is $50,0000.");
   
    for(new i = 0; sizeof(HouseData); i++)
    {
        if(HouseData[i][Created] == 0) houseid = i;
    }

    if(houseid == 999) return SendClientMessage(playerid, C_SYNTAX, "Error: {FFFFFF} There are no more house slots left.");

    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, A);
   
    HouseData[houseid][Created] = 0;
    HouseData[houseid][Entrance][0] = A;
    HouseData[houseid][Entrance][1] = X;
    HouseData[houseid][Entrance][2] = Y;
    HouseData[houseid][Entrance][3] = Z;
    HouseData[houseid][Interior] = interior;
    HouseData[houseid][ForSale] = true;
    HouseData[houseid][SalePrice] = price;
    strmid(HouseData[houseid][Owner], "The Real Estate", 0, 255);
   
    HouseData[houseid][ForSaleSign] = CreateDynamicObject(19470, HouseData[houseid][Entrance][1], HouseData[houseid][Entrance][2], HouseData[houseid][Entrance][3], 0.0, 0.0, 0.0, 0);
    SetObjectFaceCoords3D(HouseData[houseid][ForSaleSign], X, Y, Z, 0.0, 180.0, 90.0);
    return 1;
}
Where the warning shows:
pawn Код:
for(new i = 0; sizeof(HouseData); i++)
    {
        if(HouseData[i][Created] == 0) houseid = i;
    }



Re: redundant test: constant expression is non-zero - Borg - 14.11.2013

pawn Код:
for(new i = 0; sizeof(HouseData); i++)
    {
        if(HouseData[i][Created] == 0) houseid = i;
    }
you use "sizeof(HouseData)" as condition; i think you want to have
pawn Код:
for(new i = 0; i < sizeof(HouseData); i++)
{
     if(HouseData[i][Created] == 0) houseid = i;
}



Re: redundant test: constant expression is non-zero - Jack_Leslie - 15.11.2013

Quote:
Originally Posted by Borg
Посмотреть сообщение
pawn Код:
for(new i = 0; sizeof(HouseData); i++)
    {
        if(HouseData[i][Created] == 0) houseid = i;
    }
you use "sizeof(HouseData)" as condition; i think you want to have
pawn Код:
for(new i = 0; i < sizeof(HouseData); i++)
{
     if(HouseData[i][Created] == 0) houseid = i;
}
Oh shit, how stupid of me. Didn't even see that. Thanks heaps