AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help|Variables (https://forums.alliedmods.net/showthread.php?t=167797)

Dr7sTyLe 09-20-2011 10:01

Help|Variables
 
Hey,
I want to know what the part in bold means :
Quote:

new gVariable [32] [33]
the first one i know its the chars but the second one why and when do u use it

e12harry 09-20-2011 10:46

Re: Help|Variables
 
I would say that the second one is chars.
PHP Code:

new gVariable [32] [33

means that you can store32 items (strings) and each can have up to 32 chars (if you wans to store strings, othevice you can store 33 numbers).
For example you can store player names:
PHP Code:

new maxPlayers get_maxplayers();
    
    for(new 
i=1;i<maxPlayers;i++){
        if(
is_user_connected(i)){
            
get_user_name(igVariable[i], 32);
        }
    } 


Bugsy 09-20-2011 16:34

Re: Help|Variables
 
The above code will error if a player connected on slot # 32 since the first dimension is sized 32 which leaves the upper boundary of the array 31, it should be sized 33.

Its called a 2-dimension array.

Var[] = 1 dimension
Var[][] = 2 dimension

For each item in the first dimension you have dimension-2 cells of storage. These are used for storing various types of data and commonly used for string arrays since each letter occupies a cell.

Var[ 4 ][ 10 ]

Here you have essentially 4 arrays each sized at 10 cells.

Here is a graphic I found that may help
http://comscigate.com/Books/IntroSed...ay/array2d.png


All times are GMT -4. The time now is 19:40.

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