Raised This Month: $ Target: $400
 0% 

[Question] Players.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
1liornatan
Member
Join Date: Sep 2010
Old 09-24-2012 , 10:38   [Question] Players.
Reply With Quote #1

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?
1liornatan is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 09-24-2012 , 10:46   Re: [Question] Players.
Reply With Quote #2

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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 09-24-2012 , 10:54   Re: [Question] Players.
Reply With Quote #3

PHP Code:
new iPlayers[32
If you count from 0 to 32 you will get exactly 33.
SpeeDeeR is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 09-24-2012 , 11:53   Re: [Question] Players.
Reply With Quote #4

Quote:
Originally Posted by SpeeDeeR View Post
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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
1liornatan
Member
Join Date: Sep 2010
Old 09-25-2012 , 04:18   Re: [Question] Players.
Reply With Quote #5

so should i use 33?
1liornatan is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 09-25-2012 , 04:31   Re: [Question] Players.
Reply With Quote #6

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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 09-25-2012 , 12:06   Re: [Question] Players.
Reply With Quote #7

Quote:
Originally Posted by Liverwiz View Post
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.
SpeeDeeR is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 09-25-2012 , 14:15   Re: [Question] Players.
Reply With Quote #8

index 0 or id value 0 is worldspawn entity.
1=>32+1=33, why +1 ( 0 is also a number )

Last edited by .Dare Devil.; 09-25-2012 at 14:15.
.Dare Devil. is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 09-25-2012 , 14:59   Re: [Question] Players.
Reply With Quote #9

Quote:
Originally Posted by SpeeDeeR View Post
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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 09-25-2012 , 19:32   Re: [Question] Players.
Reply With Quote #10

Quote:
Originally Posted by SpeeDeeR View Post
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.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply



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

Forum Jump


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


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