Raised This Month: $ Target: $400
 0% 

Help|Variables


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr7sTyLe
Senior Member
Join Date: Dec 2010
Old 09-20-2011 , 10:01   Help|Variables
Reply With Quote #1

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
Dr7sTyLe is offline
e12harry
Member
Join Date: Apr 2010
Old 09-20-2011 , 10:46   Re: Help|Variables
Reply With Quote #2

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);
        }
    } 
e12harry is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-20-2011 , 16:34   Re: Help|Variables
Reply With Quote #3

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
__________________

Last edited by Bugsy; 09-20-2011 at 16:37.
Bugsy is online now
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 19:40.


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