SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 28/02/2010, 08:23 AM   #1
Gozerr
Little Clucker
 
Join Date: Jul 2008
Posts: 33
Reputation: 0
Default Help with arrays

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?
Gozerr is offline  
Old 28/02/2010, 09:06 AM   #2
Gozerr
Little Clucker
 
Join Date: Jul 2008
Posts: 33
Reputation: 0
Default Re: Help with arrays

I really need this.
Gozerr is offline  
Old 28/02/2010, 10:36 AM   #3
adsy
Huge Clucker
 
Join Date: Aug 2008
Posts: 410
Reputation: 3
Default Re: Help with arrays

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()
adsy is offline  
Old 28/02/2010, 01:07 PM   #4
Gozerr
Little Clucker
 
Join Date: Jul 2008
Posts: 33
Reputation: 0
Default Re: Help with arrays

Ah thanks.
Gozerr is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Arrays •Ajax• Help Archive 3 28/11/2009 06:40 AM
Help With Arrays StrickenKid Help Archive 1 01/10/2009 09:01 PM
Using two or more arrays. luxeon Help Archive 13 22/04/2009 04:04 PM


All times are GMT. The time now is 12:06 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.