Return "?"
#1

Well, sorry for the unclear title but,
I've made the function "GetPlayerWithHighestScore", and it's working, but I wanna know one thing for sure.

pawn Код:
GetPlayerWithHighestScore()
{
    new HighestScore = -999999999, ID = INVALID_PLAYER_ID;
    for(new i = 0; i < 500; i++){
        if(!IsPlayerConnected(i)) continue;
        if(GetPlayerScore(i) > HighestScore){
            HighestScore = GetPlayerScore(i);
            ID = i;
        }
        continue;
    }
    return ID != INVALID_PLAYER_ID ? ID : -1;
}
About the return ID != INVALID_PLAYER_ID ? ID : -1;
Am I true, if I say that this means...
Return "ID" when it's not 'INVALID_PLAYER_ID', otherwise, return '-1'
Just wanna know for sure :P - I like scripting etc, and I'm a bit good with it, but I just wanna know for sure... I wanna understand ANYTHING I make

Thanks in advance,
Kevin
Reply
#2

You can just do
pawn Код:
return ID;
because it can't possibly be anything else other than -1 through 499.

BTW -1 == INVALID_PLAYER_ID
Reply
#3

Eh, actually that didn't work - I've done that before, and it did always return '1', even when I was alone (so, ID 0).
And btw, INVALID_PLAYER_ID is " (0xFFFF) " in a_samp :P
But thanks for your response - But about what I asked, is that true?

Quote:
Return "ID" when it's not 'INVALID_PLAYER_ID', otherwise, return '-1'
Reply
#4

pawn Код:
stock GetPlayerWithHighestScore()
{
    new
        scoreMax = cellmin,
        scoreTemp,
        playerid = -1
    ;
    for(new i; i != MAX_PLAYERS; ++i)
    {
        if(IsPlayerConnected(i))
        {
            if((scoreTemp = GetPlayerScore(i)) > scoreMax)
            {
                scoreMax = scoreTemp;
                playerid = i;
            }
        }
    }
    return playerid;
}
This one works perfect. Actually you don't need the ? : statement because it'll return -1 as long as you don't assign anything, so actually, if there's no player connected it'll return -1.
Reply
#5

Quote:

if there's no player connected it'll return -1.

I know, that's what I wanted :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)