Quote:
Originally Posted by MAGNAT2645
Code:
char g_sItems1[][] = {
"ABC",
"DEF",
"123",
"456"
};
char g_sItems2[][][] = {
{ "ABC", "DEF" },
{ "123", "456" },
{ "789", "QWE" }
};
public void OnPluginStart()
{
for ( int i = 0; i < sizeof g_sItems1; i++ )
PrintToServer( "%s", g_sItems1[i] );
PrintToServer( "---" );
for ( int i = 0, j; i < sizeof g_sItems2; i++ ) {
for ( j = 0; j < sizeof g_sItems2[]; j++ )
PrintToServer( "%s", g_sItems2[i][j] );
}
}
Note that each row in 2D string array must have same number of strings (that's due to how compiler works).
If you want to have, for example, 2 strings in 1st row and 4 strings in 2nd row you can just put empty strings:
Code:
char g_sItems2[][][] = {
{ "ABC", "DEF", "", "" },
{ "123", "456", "GGG", "RRR" }
};
|
Well, I have this idea too. However, I rejected that idea in a second.
When the length of the max is extended, I have to add the empty string for each array to match the size. If I have 100 arrays of it, I have to do it 100 times...
In this stage, I have two better ideas.
Code:
// --First way is split the 2D string array to 1D string array, and pushing it into array list.
char g_sMelees[][] =
{ // Melee ID:
"katana", // 0
"fireaxe", // 1
"machete", // 2
"flamethrower", // 3
"knife", // 4
"chainsaw", // 5
"pitchfork", // 6
"shovel", // 7
"golfclub", // 8
"electric_guitar", // 9
"tonfa", // 10
"baseball_bat", // 11
"cricket_bat", // 12
"frying_pan", // 13
"crowbar", // 14
};
ArrayList g_listItems[SHOP_SIZE];
enum
{ ...
SHOP_MELEES = 8,
...
SHOP_SIZE = 17,
};
public void OnPluginStart()
{
for(int i=0; i<SHOP_SIZE; i++)
g_listItems[i] = new ArrayList(ByteCountToCells(32));
// melee weapons
for(int i=0; i<sizeof(g_sMelees); i++) g_listItems[SHOP_MELEES].PushString(g_sMelees[i]);
// --Second way, don't use the char array to declare, pushing the value to array list instead of it
g_listItems[SHOP_MELEES].PushString("katana");
g_listItems[SHOP_MELEES].PushString("fireaxe");
//...
}