Loop Help?
#7

Just loop through it and stop if the xp required is lower or equal to the player exp
pawn Код:
GetRank(exp, rank = 0) {
    if(exp < Ranks[0][RankXP]) {
        return 0;
    }
    if(!(0 <= rank < sizeof Ranks) || (exp < Ranks[rank][RankXP])) {
        rank = 0;
    }
    while((rank < sizeof Ranks) && (Ranks[rank][RankXP] <= exp)) rank++;

    return rank - 1;
}
Using a switch is only possible if you check each time the player gets experience (you should do that anyways)
And the important fact, it will only work if you only add constant numbers which will match the values in the switch
Reply


Messages In This Thread
All my Questions - by newbie scripter - 08.12.2013, 11:42
Re: Loop Help? - by Voxel - 08.12.2013, 11:55
Re: Loop Help? - by newbie scripter - 08.12.2013, 12:30
Re: Loop Help? - by Voxel - 08.12.2013, 12:52
Re: Loop Help? - by newbie scripter - 08.12.2013, 12:58
Re: Loop Help? - by Voxel - 08.12.2013, 13:05
AW: Loop Help? - by Nero_3D - 08.12.2013, 13:11
Re: Loop Help? - by newbie scripter - 08.12.2013, 13:30
Re: Loop Help? - by Stevo127 - 08.12.2013, 13:40
Re: Loop Help? - by newbie scripter - 08.12.2013, 14:31

Forum Jump:


Users browsing this thread: 1 Guest(s)