SA-MP Forums Archive
Local 2- and 3-dimensional arrays - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Local 2- and 3-dimensional arrays (/showthread.php?tid=200893)



Local 2- and 3-dimensional arrays - MadeMan - 19.12.2010

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.


Re: Local 2- and 3-dimensional arrays - Joe_ - 19.12.2010

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


Re: Local 2- and 3-dimensional arrays - MadeMan - 19.12.2010

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


Re: Local 2- and 3-dimensional arrays - DeadAhead - 29.04.2011

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;
}



Re: Local 2- and 3-dimensional arrays - xir - 29.04.2011

Код:
But it shouldn't ??

Because arrays are in different scope.
??


Re: Local 2- and 3-dimensional arrays - MadeMan - 29.04.2011

It doesn't give error on /test1


Re: Local 2- and 3-dimensional arrays - KoczkaHUN - 29.04.2011

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.


Re: Local 2- and 3-dimensional arrays - Babul - 29.04.2011

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)
	{
		//...
	}