AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Multidimensional array (https://forums.alliedmods.net/showthread.php?t=251638)

~Ice*shOt 11-16-2014 11:14

Multidimensional array
 
Why it prints like

Quote:

1. 1 First
2. 2 First
3. 3 First
I want

Quote:

1. 1 First
2. 1 Second
3. 1 Third
4. 1 Fourth
PHP Code:

#define MAX_CATEGORIES 3

new const g_iMaxNames[MAX_CATEGORIES] = { 42};

new const 
g_szNames[][] =
{
    { 
"1 First""1 Second""1 Third""1 Fourth" },
    { 
"2 First""2 Second" },
    { 
"3 First""3 Second""3 Third""3 Fourth""3 Fiveth" }
};

// In menu

    
for (new 0g_iMaxNames[Selection]; i++)
    {
        new 
szItem[256];
        
formatex(szItemcharsmax(szItem), "%s"g_szNames[Selection][i]) // Know that problem is here, but I don't get it..

        
menu_additem(MenuszItem""0);
    } 


fysiks 11-16-2014 13:36

Re: Multidimensional array
 
That can't even compile . . . also, that is a 3 dimensional array so you need to add a dimension to the declaration.

~Ice*shOt 11-16-2014 13:41

Re: Multidimensional array
 
Why it can't? I understand, that it's not full code but it compiles at all.
How should look this line if I add 3rd dimension?
PHP Code:

formatex(szItemcharsmax(szItem), "%s"g_szNames[Selection][i


fysiks 11-16-2014 13:50

Re: Multidimensional array
 
You don't need to chagne that line (if I'm not mistaken), you only need to add a third dimension to the declaration of the array.

~Ice*shOt 11-16-2014 14:02

Re: Multidimensional array
 
There is how it looks added one more dimension

PHP Code:

new const g_szNames[][][] =
{
    { 
"1 First""1 Second""1 Third""1 Fourth""" },
    { 
"2 First""2 Second""""" },
    { 
"3 First""3 Second""3 Third""3 Fourth""3 Fiveth" }
}; 

It is possible to prevent that ""? Because without them I am getting

Quote:

error 052: multi-dimensional arrays must be fully initialized

YamiKaitou 11-16-2014 14:30

Re: Multidimensional array
 
Quote:

Originally Posted by ~Ice*shOt (Post 2225061)
It is possible to prevent that ""? Because without them I am getting

No, you must always fully initialize an array


All times are GMT -4. The time now is 17:42.

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