Problems on strings of an enumerator of a 2D array -
leong124 - 17.05.2011
I recently find a new problem on 2D array again.
pawn Код:
enum test
{
test1,
test2[128]
}
public OnFilterScriptInit()
{
new testarr[test] =
{
1,"hello world!"
};
print(testarr[test2]);
testarr[test2][0] = '\0';
format(testarr[test2],sizeof(testarr[test2]),"helloworld!!");
print(testarr[test2]);
return 1;
}
Works fine and you can change the values of testarr[test2],
but when the testarr goes 2D,
pawn Код:
[enum test
{
test1,
test2[128]
}
public OnFilterScriptInit()
{
new testarr[1][test] =
{
{1,"hello world!"}
};
print(testarr[0][test2]);
testarr[0][test2][0] = '\0';
format(testarr[0][test2],sizeof(testarr[0][test2]),"helloworld!!");//Line 31
print(testarr[0][test2]);
return 1;
}
Gives out compiler errors:
Код:
C:\Program Files\Rockstar Games\GTA San Andreas\filterscripts\test.pwn(31) : error 001: expected token: "]", but found "-integer value-"
C:\Program Files\Rockstar Games\GTA San Andreas\filterscripts\test.pwn(31) : warning 215: expression has no effect
C:\Program Files\Rockstar Games\GTA San Andreas\filterscripts\test.pwn(31) : error 001: expected token: ";", but found "]"
C:\Program Files\Rockstar Games\GTA San Andreas\filterscripts\test.pwn(31) : error 029: invalid expression, assumed zero
C:\Program Files\Rockstar Games\GTA San Andreas\filterscripts\test.pwn(31) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
All errors occurs on that format(trying to change the value of that string).
Single cell access seems to be working but you can't change the whole string.
Weird..
Re: Problems on strings of an enumerator of a 2D array -
Backwardsman97 - 17.05.2011
I think it's because PAWN only supports 2 dimensional arrays and when you have a string, inside an enumeration, inside a 2D array, it kinda acts as a 3D array so pawno freaks out.
Re: Problems on strings of an enumerator of a 2D array -
Vince - 17.05.2011
Pawn supports arrays up to 3 dimensions ...
Re: Problems on strings of an enumerator of a 2D array -
Joe Staff - 17.05.2011
I have always had this issue, just use strcat or strmid on it.
Re: Problems on strings of an enumerator of a 2D array -
leong124 - 17.05.2011
I find the only problem is that sizeof for strings in enumator types will not work,
causing strcat/format,etc. don't work(since they need the size of the string).
If you specify their size, for example 128, it will work.
And yeah, PAWN starts to fail when there's multi-dimensional arrays(even 2D array).
I've found this problem long time ago:
pawn Код:
new i;
switch(i)
{
case 0:
{
new string[2][128];
string[0][0] = '\0';
}
default:
{
new string[2][128];
string[0][0] = '\0';
}
}
Try to compile it
Edit:
This thread is posted long time ago, but I still have to say that I found the solution. That's a fault of not understanding the actual format:
pawn Код:
format(testarr[0][test2],sizeof(testarr[][]),"helloworld!!");
It should work, but still, the switch problem above is indeed a bug.