Jump to content
  • Advertisement
Sign in to follow this  
coderchris

bug with AS classes and question about arrayss

This topic is 4001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!