Local 2- and 3-dimensional arrays
#1

I made 3 example commands

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/test1", true) == 0)
    {
        new array[16][32];
        array[5] = "Testing command 1";
        SendClientMessage(playerid, 0xFFFFFFFF, array[5]);
        return 1;
    }
    if(strcmp(cmdtext, "/test2", true) == 0)
    {
        new array[16][32];
        array[5] = "Testing command 2";
        SendClientMessage(playerid, 0xFFFFFFFF, array[5]);
        return 1;
    }
    if(strcmp(cmdtext, "/test3", true) == 0)
    {
        new array[16][32];
        array[5] = "Testing command 3";
        SendClientMessage(playerid, 0xFFFFFFFF, array[5]);
        return 1;
    }
    return 0;
}
And it gives 2 errors on /test2 and /test3:

Код:
error 021: symbol already defined: "array"
error 021: symbol already defined: "array"
But it shouldn't ??

Because arrays are in different scope.
Reply
#2

I had the same problem today. I wondered the same thing, just changed the mask though, lol.
Reply
#3

Looks like it's a PAWN bug then. Can someone fix it?
Reply
#4

Most likely the problem is you have the same variable names


pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new array[16][32];
    if(strcmp(cmdtext, "/test1", true) == 0)
    {    
        array[5] = "Testing command 1";
        SendClientMessage(playerid, 0xFFFFFFFF, array[5]);
        return 1;
    }
    if(strcmp(cmdtext, "/test2", true) == 0)
    {
        array[5] = "Testing command 2";
        SendClientMessage(playerid, 0xFFFFFFFF, array[5]);
        return 1;
    }
    if(strcmp(cmdtext, "/test3", true) == 0)
    {
        array[5] = "Testing command 3";
        SendClientMessage(playerid, 0xFFFFFFFF, array[5]);
        return 1;
    }
    return 0;
}
Reply
#5

Код:
But it shouldn't ??

Because arrays are in different scope.
??
Reply
#6

It doesn't give error on /test1
Reply
#7

I can reproduce this bug with other variables too. If I create a bi-dimensional array in the first command, and create a variable called e.g. "var1", and I attempt to create a variable called "var1" in the 2nd or 3rd command, it throws an error that "var1" is already defined. It just happens if I create the two-dimensional array, otherwise not.

I can confirm that there isn't "var1" at higher levels.
Reply
#8

didnt check it out, just an idea:
Код:
	if(strcmp(cmdtext, "/test1", true) == 0)
	{
		//...
	}
	else if(strcmp(cmdtext, "/test2", true) == 0)
	{
		//...
	}
	else if(strcmp(cmdtext, "/test3", true) == 0)
	{
		//...
	}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)