# bug with AS classes and question about arrayss

## Recommended Posts

coderchris    304
I found a little bug with the latest (2.8.1) when writing a class in AS; I think it deals with the compiler: Basically, when you are declaring two of the same variable type seperated by a comma, it thinks there should be a semicolon. For example, The following code will compile fine:
class Vec2
{
float x;
float y;
}

However, this code will not compile and gives a "expected ';'" error:
class Vec2
{
float x,y;
}

I tested using the comma outside a class declaration and it works fine ---------question about arrays--------- I was messing around with the arrays, and i wanted to test if it could do 2 dimensional arrays, so i wrote:
void main()
{
float[][] arr = { {10, 11, 12}, {13, 14, 15} };

for (int i=0;i<arr.length();i++)
{
for (int j=0;j<arr[0].length();j++)
{
print("" + arr[i][j] + " ");
}
println("");
}
}
//print and println, btw, are functions I had registered from c++

And interstingly enough, it gave me a couple errors, regarding the for loops, but ran just as you would expect afterwards, printing out the numbers just right Heres the errors it game me: Error at Line 5, Position 16 Signed/Unsigned mismatch Error at Line 7, Position 17 Signed/Unsigned mismatch I also noted that no matter how many ways i tried, i couldnt seem to declare a 2d array without initializing it first, so something like: float[][] arr(3,2); would always give me an error.. So anyways, my questions are, what is the proper way to code those for loops so that i dont get the error, and is there a way to declare an empty 2d array?

##### Share on other sites
WitchLord    4677
This is not a bug. This is how I designed it to work. However, I may allow comma separated member declarations in the future.

The compiler message is not an error, just a warning. You're getting the signed/unsigned mismatch because the array length() method returns an unsigned int. Either use unsigned int as the iteration variable, or cast the returned value before comparison to avoid this warning.

You declare the empty 2D array without the 2nd dimension and then resize each sub array.

float[][] arr(3);arr[0].resize(2);arr[1].resize(2);arr[2].resize(2);

Obviously the way you tried to create the array is more intuitive, but I still need to implement support for this.

Regards,
Andreas

##### Share on other sites
coderchris    304
Ah ok, that explains it. I see now that one of those error code things in the structure tells if its an error or warning; I should have checked that instead of assuming they were all errors :P

Is there any quick and easy way that I could modify it myself to allow the comma in member declaration?

##### Share on other sites
WitchLord    4677
You'll have to change the as_parser.cpp and the as_builder.cpp to support the comma separated members. It shouldn't be too difficult, I would do it myself I had the time.

Regards,
Andreas

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account