What's the difference?
#1

I've got this on a script , and i don't know why he use more than return 1 +

pawn Код:
public HouseLevel(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        new h = PlayerInfo[playerid][pPhousekey];
        if(h == 500)
        {
            return 0;
        }
        if(h <= 4)
        {
            return 1;
        }
        if(h >= 5 && h <= 9)
        {
            return 2;
        }
        if(h >= 10 && h <= 18)
        {
            return 3;
        }
        if(h >= 19 && h <= 22)
        {
            return 4;
        }
        if(h >= 23 && h <= 25)
        {
            return 5;
        }
        if(h == 26)
        {
            return 6;
        }
        if(h == 27)
        {
            return 7;
        }
        if(h >= 28 && h <= 31)
        {
            return 7;
        }
        if(h >= 32 && h <= 67)
        {
            return 8;
        }
    }
    return 0;
}
Why he use return 2 , 3 , 4, 5, 6, 7, 8 !?
It's not the same difference ?
Reply
#2

Hard to explain :S, Dunno how even :\
Reply
#3

so

return 1 isn't = with return 2+ ?
Reply
#4

Function always returns only 1 value and it could be everything, but the same type.

pawn Код:
if(h == 500)
    {
        return 0;
    }
it's useless.

anyway it'll be simplier to create it with switch/case construction.

Edit: evil post
Reply
#5

Quote:
Originally Posted by Danut
I've got this on a script , and i don't know why he use more than return 1 +

pawn Код:
public HouseLevel(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        new h = PlayerInfo[playerid][pPhousekey];
        if(h == 500)
        {
            return 0;
        }
        if(h <= 4)
        {
            return 1;
        }
        if(h >= 5 && h <= 9)
        {
            return 2;
        }
        if(h >= 10 && h <= 18)
        {
            return 3;
        }
        if(h >= 19 && h <= 22)
        {
            return 4;
        }
        if(h >= 23 && h <= 25)
        {
            return 5;
        }
        if(h == 26)
        {
            return 6;
        }
        if(h == 27)
        {
            return 7;
        }
        if(h >= 28 && h <= 31)
        {
            return 7;
        }
        if(h >= 32 && h <= 67)
        {
            return 8;
        }
    }
    return 0;
}
Why he use return 2 , 3 , 4, 5, 6, 7, 8 !?
It's not the same difference ?
its like, if your housekey is like the first one 500, your house level will be 0 because it returns on 0
Reply
#6

It's a way of figuring out a house's level.

It returns a different number so it can be used in a conditional
for example
pawn Код:
if(HouseLevel(playerid)<3)
{
  return SendClientMessage(playerid,0xFF0000FF,"Your house is not high enough level to use this upgrade");
}
Reply
#7

you can return anything you want, 0 will make it pass using the !
pawn Код:
if(!Function(0))
pawn Код:
Function(params)
{
return params;
}
or

pawn Код:
if(Function(5))
that would pass but
pawn Код:
if(Function(4) == 3)
would not pass
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)