enum of array of string doesn't write strings properly
#1

I can't understand why this code doesn't work properly. Can anyone explain me why and how to fix it?

Code:
enum eTest {
	pString1[128],
	pString2[128]
};

new TEST[3][eTest] =
{
	{"This is a test i have named as A1", "This is a test i have named as B1"},
	{"This is a test i have named as A2", "This is a test i have named as B2"},
	{"This is a test i have named as A3", "This is a test i have named as B2"}
}

new TEST_ARRAY[][3][eTest] =
{
	{
		{"This is a test i have named as 1-A1", "This is a test i have named as 1-B1"},
		{"This is a test i have named as 1-A2", "This is a test i have named as 1-B2"},
		{"This is a test i have named as 1-A3", "This is a test i have named as 1-B2"}
	},
	{
		{"This is a test i have named as 2-A1", "This is a test i have named as 2-B1"},
		{"This is a test i have named as 2-A2", "This is a test i have named as 2-B2"},
		{"This is a test i have named as 2-A3", "This is a test i have named as 2-B2"}
	},
	{
		{"This is a test i have named as 3-A1", "This is a test i have named as 3-B1"},
		{"This is a test i have named as 3-A2", "This is a test i have named as 3-B2"},
		{"This is a test i have named as 3-A3", "This is a test i have named as 3-B2"}
	}
};

main()
{
        // This works at expected
	for (new i=0; i<sizeof(TEST_ARRAY); i++) {
 		printf("%s <--> %s", TEST[i][pString1], TEST[i][pString2]);
	}
	
	printf("----");
	printf("");
	printf("----");
	
       // In this prints strings are not completes :S Why?
	for (new i=0; i<sizeof(TEST_ARRAY); i++) {
	    for (new j=0; j<sizeof(TEST_ARRAY[]); j++) {
	        printf("%s <--> %s", TEST_ARRAY[i][j][pString1], TEST_ARRAY[i][j][pString2]);
	    }
	}
}
This is the output:

Code:
This is a test i have named as A1 <--> This is a test i have named as B1
This is a test i have named as A2 <--> This is a test i have named as B2
This is a test i have named as A3 <--> This is a test i have named as B2
----

----
 test i have named as 1-A1 <-->  test i have named as 1-B1
 test i have named as 1-A2 <-->  test i have named as 1-B2
 test i have named as 1-A3 <-->  test i have named as 1-B2
 test i have named as 2-A1 <-->  test i have named as 2-B1
 test i have named as 2-A2 <-->  test i have named as 2-B2
 test i have named as 2-A3 <-->  test i have named as 2-B2
 test i have named as 3-A1 <-->  test i have named as 3-B1
 test i have named as 3-A2 <-->  test i have named as 3-B2
 test i have named as 3-A3 <-->  test i have named as 3-B2
Reply
#2

for (new i=0; i<sizeof(TEST_ARRAY); i++)

change in

for (new i1=0; i1<sizeof(TEST_ARRAY); i1++)

And why :

You use same name variable in same loop and when you call you second for i change to new i = 0
and loop reset him self .
Reply
#3

Thats likely a bug within the compiler because these work fine
pawn Code:
new TEST_ARRAY[][][eTest] =
new TEST_ARRAY[3][][eTest] =
new TEST_ARRAY[3][3][eTest] =
Also using enum arrays with constant text is just a waste because the cells you dont use are still declared resulting in huge blocks of unused memory
Reply
#4

Quote:
Originally Posted by Nero_3D
View Post
Thats likely a bug within the compiler because these work fine
pawn Code:
new TEST_ARRAY[][][eTest] =
new TEST_ARRAY[3][][eTest] =
new TEST_ARRAY[3][3][eTest] =
Also using enum arrays with constant text is just a waste because the cells you dont use are still declared resulting in huge blocks of unused memory
What would we the solution to that problem?
Reply
#5

Quote:
Originally Posted by Azazelo
View Post
for (new i=0; i<sizeof(TEST_ARRAY); i++)

change in

for (new i1=0; i1<sizeof(TEST_ARRAY); i1++)

And why :

You use same name variable in same loop and when you call you second for i change to new i = 0
and loop reset him self .
That's not the problem, those loops works just fine, but thanks for the answer.
Reply
#6

Pawn only supports up to 3 dimensions.
Reply
#7

new TEST_ARRAY[3][3][eTest] =

seems to fix the problem
Reply
#8

Quote:
Originally Posted by trollkemada
View Post
What would we the solution to that problem?
All three of them I posted but personally I would use this because its the easiest
pawn Code:
new TEST_ARRAY[][][eTest] =
Than I would remove the enum and add the data like that
pawn Code:
stock const TEST_ARRAY[][][] = {
    {
        "This is a test i have named as 1-A1", "This is a test i have named as 1-B1",
        "This is a test i have named as 1-A2", "This is a test i have named as 1-B2",
        "This is a test i have named as 1-A3", "This is a test i have named as 1-B3"
    }, {
        "This is a test i have named as 2-A1", "This is a test i have named as 2-B1",
        "This is a test i have named as 2-A2", "This is a test i have named as 2-B2",
        "This is a test i have named as 2-A3", "This is a test i have named as 2-B3"
    }, {
        "This is a test i have named as 3-A1", "This is a test i have named as 3-B1",
        "This is a test i have named as 3-A2", "This is a test i have named as 3-B2",
        "This is a test i have named as 3-A3", "This is a test i have named as 3-B3"
    }
};
pawn Code:
main() {
    for(new i, j; i < sizeof TEST_ARRAY; ++i) {
        for(j = 0; j < sizeof TEST_ARRAY[]; j += 2) { // + 2 !!!
            printf("%s <--> %s", TEST_ARRAY[i][j], TEST_ARRAY[i][j + 1]);
        }
    }
}
Old amx size 2996 Bytes, new amx size 1378 Bytes (only compiled this array and the loop)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)