SA-MP Forums Archive
Assigning to array, finding nearest empty spot - 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: Assigning to array, finding nearest empty spot (/showthread.php?tid=416797)



Assigning to array, finding nearest empty spot - Misiur - 18.02.2013

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