Initializing arrays, ellipsis -
Baltazar - 07.03.2016
Let's first declare and initialize one-dimensional and two-dimensional arrays on a global scale
Код:
new a[10] = {1, ...};
new b[10][2] = {{1, 1}, ...};
Nice, works well. Now let's do the same inside any function (for example inside of main() ) with a one-dimensional array.
Код:
main(){
new a[10] = {1, ...};
}
So far so good. Now let's try it out with a two-dimensional array
Код:
main(){
new b[10][2] = {{1, 1}, ...};
}
Nope, not working. Getting this kind of error
Код:
C:\blablabla\gamemodes\test.pwn(9) : error 029: invalid expression, assumed zero
What's the problem? How do I initialize two-dimensional arrays (using ellipsis!) inside of a function?
Re: Initializing arrays, ellipsis -
SickAttack - 08.03.2016
You are going to have to specify the exact amount of
slots/cells/w/e being used.
e.g.
pawn Код:
new b[2][5] =
{
{1, 1},
{2, 2}
};
What are you trying to do with this anyway?
Re: Initializing arrays, ellipsis -
Crayder - 08.03.2016
In Zeex's compiler this will work. With the SA-MP compiler that comes with the SA-MP package (the one you have obviously) you are stuck doing what SickAttack did.
Re: Initializing arrays, ellipsis -
Baltazar - 08.03.2016
Quote:
Originally Posted by Crayder
In Zeex's compiler this will work. With the SA-MP compiler that comes with the SA-MP package (the one you have obviously) you are stuck doing what SickAttack did.
|
Just tried Zeex's compiler out. Works well on an empty project, but crashes on my actual project. And SA-MP's compiler does not

any known issues? Why could this be happening?
Re: Initializing arrays, ellipsis -
Baltazar - 08.03.2016
Ok, just tried a newer version of Zeex's compiler. It doesn't crash (that means previous release was bugged), but does't compile either. It throws a fatal error saying, that <a_samp> has to be included before <sscanf2>. And <a_samp> is included before <sscanf2>. Such kind of errors are ridiculous, not happy
Re: Initializing arrays, ellipsis -
Crayder - 08.03.2016
Quote:
Originally Posted by Baltazar
Ok, just tried a newer version of Zeex's compiler. It doesn't crash (that means previous release was bugged), but does't compile either. It throws a fatal error saying, that <a_samp> has to be included before <sscanf2>. And <a_samp> is included before <sscanf2>. Such kind of errors are ridiculous, not happy 
|
I don't have that issue so it must be something to do with your script, perhaps the overall include order even.
Re: Initializing arrays, ellipsis -
Slice - 10.03.2016
You're running into problems because of the include guards. Try compiling with -Z or just do this:
pawn Код:
#include <a_samp>
#define _inc_a_samp
#include <sscanf2>
Not sure if there is an official update to the include that has a better check for previous inclusion.