AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   some questions (https://forums.alliedmods.net/showthread.php?t=171755)

Tomusaki 11-10-2011 13:50

some questions
 
Hello all,
As i said in another theme i'm learning scripting, and i need help from you.
So my questions are:
1.) what does the number in new variables means ? For example: new guns[33], new grenades[33], new maxplayers[33] and etc..
2.) What does cid means ?
Thats all for now, if i have more questions i will post them in to this theme.
Thank you for answers!

KillLikoe 11-10-2011 19:34

Re: some questions
 
1- the size of the cells, in that variables the size is 33 because it have to contain all the player`s index, start from 1 until 32 and you have to left a cell i dont know why

Devil259 11-10-2011 19:37

Re: some questions
 
http://wiki.amxmodx.org/Pawn_Tutorial#Arrays

drekes 11-10-2011 20:08

Re: some questions
 
Quote:

Originally Posted by KillLikoe (Post 1594270)
1- the size of the cells, in that variables the size is 33 because it have to contain all the player`s index, start from 1 until 32 and you have to left a cell i dont know why

Arrays start from 0.

KillLikoe 11-10-2011 20:20

Re: some questions
 
Quote:

Originally Posted by drekes (Post 1594283)
Arrays start from 0.

i was talking about, why to use number 33 for global variables, but yes it starts from zero

Bugsy 11-10-2011 20:35

Re: some questions
 
Quote:

Originally Posted by KillLikoe (Post 1594270)
1- the size of the cells, in that variables the size is 33 because it have to contain all the player`s index, start from 1 until 32 and you have to left a cell i dont know why

@KillLikoe

The size of a cell is 4-bytes which cannot be changed, it would be better to say 33 is the size of the array. I know what you meant to say but its best to try and not confuse people.

"and you have to left a cell i dont know why"

See below, though you are correct, a cell is wasted which is index 0 since 0 is not a valid player index, only 1-32 is.

@KillLikoe & Tomusaki

The most common reason for seeing arrays sized at 33 (or MAXPLAYERS+1) is for storing data for each individual player using the player-index as the array index. When you need to index an array you start at 0 and go up to size-1, so if an array is sized at var[33] you can do var[0] up to var[32] to access each item; index 0 counts as an item in the array so index 32 is the 33rd cell. Player indexes in HL\CS range from 1 to 32 so you need an array sized at 33 (or larger) to make it possible to store/retrieve player info like var[ player-id ].


All times are GMT -4. The time now is 14:25.

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