Assigning to array, finding nearest empty spot
#1

Hello. So I was wandering if there is a native way in pawn to assign to first empty field. Currently I can only think about either holding last index in a variable (but this will always be top of stack), or looping through array and finding the spot like this

pawn Код:
new bool:Wafflez[MAX_PLAYERS char];
//(...)
stock GetNearestSpot() {
    for(new i = 0; i != MAX_PLAYERS; ++i) {
        if(!Wafflez{i}) return i;  
    }
    return -1;
}
//(...)
printf("Current index: %d", GetNearestSpot()); //Current index: 0
for(new i = 0; i != 5; ++i) { Wafflez{i} = true; };
printf("Current index: %d", GetNearestSpot()); //Current index: 5
Wafflez{2} = false;
printf("Current index: %d", GetNearestSpot()); //Current index: 2
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)