Advertisement

bug with AS classes and question about arrayss

Started by August 03, 2007 01:31 AM
2 comments, last by WitchLord 17 years, 4 months ago
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[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?
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
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?
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement