AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Question] Players. (https://forums.alliedmods.net/showthread.php?t=196692)

1liornatan 09-24-2012 10:38

[Question] Players.
 
hey...
how should it be?
PHP Code:

new player[32]
get_players(...) 

or
PHP Code:

new player[33]
get_players(...) 

now i think that i should put 32 cause player0 - player31 are 32 players
but i get an index out of bounds error on my plugin...
so what do you think?

Liverwiz 09-24-2012 10:46

Re: [Question] Players.
 
the API is written to accept players[32] This is because index 0-31 are filled with player IDs.
However, when YOU'RE setting data for each player in your plugin, you use 33 so you have index of 1-32.

SpeeDeeR 09-24-2012 10:54

Re: [Question] Players.
 
PHP Code:

new iPlayers[32

If you count from 0 to 32 you will get exactly 33.

Liverwiz 09-24-2012 11:53

Re: [Question] Players.
 
Quote:

Originally Posted by SpeeDeeR (Post 1805278)
PHP Code:

new iPlayers[32

If you count from 0 to 32 you will get exactly 33.

Yeah....that's not how that works. If you were to call iPlayers[32] you'd get an index out of bounds.

1liornatan 09-25-2012 04:18

Re: [Question] Players.
 
so should i use 33?

YamiKaitou 09-25-2012 04:31

Re: [Question] Players.
 
get_players REQUIRES you to use 32 or you will get a compile error.

If you are using it elsewhere, 33 is common since you don't have to use id-1 each time

SpeeDeeR 09-25-2012 12:06

Re: [Question] Players.
 
Quote:

Originally Posted by Liverwiz (Post 1805305)
Yeah....that's not how that works. If you were to call iPlayers[32] you'd get an index out of bounds.

The question was about get_players() so I answered it. It has to be 32 cells.

.Dare Devil. 09-25-2012 14:15

Re: [Question] Players.
 
index 0 or id value 0 is worldspawn entity.
1=>32+1=33, why +1 ( 0 is also a number )

Liverwiz 09-25-2012 14:59

Re: [Question] Players.
 
Quote:

Originally Posted by SpeeDeeR (Post 1806014)
The question was about get_players() so I answered it. It has to be 32 cells.

The explanation you gave was misleading. But, yes, it does have to be 32.

YamiKaitou 09-25-2012 19:32

Re: [Question] Players.
 
Quote:

Originally Posted by SpeeDeeR (Post 1806014)
The question was about get_players() so I answered it. It has to be 32 cells.

Actually, it was both correct and incorrect. When you define an array with length 32, you can only use indexes 0-31. There is no 33rd index in that array.


All times are GMT -4. The time now is 08:20.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.