Help with arrays - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help with arrays (
/showthread.php?tid=130762)
Help with arrays -
Gozerr - 28.02.2010
I need to return the first empty slot in array, So i wrote this function:
pawn Code:
public GetFirstEmpty(array[])
{
new size = sizeof(array[]);
for(new a = 0; a < size; a++)
{
if(array[a] == 0)
{
return a;
}
}
return -1;
}
Problem is, When the array is empty it returns 0 (Which is correct)
But when i put something in slot 0, It returns -1.
Halp?
I think its the if(array[a] == 0)
But what should i replace the 0 with?
Or does anyone else have a working function?
Re: Help with arrays -
Gozerr - 28.02.2010
I really need this.
Re: Help with arrays -
adsy - 28.02.2010
youll need to set it as 0 somewhere before it recognises it as a 0
for example (i know this isnt using an array but its the same method)
Code:
totalon = 0;
for(new i=0; i<MAX_PLAYERS; i++) {
if(IsPlayerConnected(i)) {
if(totalon == 0){
totalon = 1;
}
else if (totalon > 0){
totalon++;
}
}
}
firstly i set it to 0 so that it can start from 0
so lets say that you need the array to be 0 at the game mode start
so run a loop that sets array[a] = 0 under OnGameModeInit()
Re: Help with arrays -
Gozerr - 28.02.2010
Ah thanks.