🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

The last comma in the initialization list counts extra elements.

Started by
4 comments, last by WitchLord 6 years, 1 month ago

void main()
{
  array<int> hoge = {
    1,
    2,
  };
  print("" + hoge.length() + "\n") ;
}

Prepare the above and execute it.


$ ./asrun.exe script2.as
3

It is expected to be 2, but 3 will be returned.

`array` uses `scriptarray addon`.

Advertisement

This is correct, uninformed elements will be left with their default values., but they still count as elements.

You can change this behaviour if you want by turning on the engine property asEP_DISALLOW_EMPTY_LIST_ELEMENTS.

 

 

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

Oh, sorry, There was a lack of confirmation.

53 minutes ago, WitchLord said:

This is correct, uninformed elements will be left with their default values., but they still count as elements.

You can change this behaviour if you want by turning on the engine property asEP_DISALLOW_EMPTY_LIST_ELEMENTS.

 

 

I'd understand this was the default behavior if there was not another item added, but as this creates another item with an undefined default value, and it seems rather unexpected, maybe it'd be better to disallow this by default?

I rather like the fact that it is possible to write lists where not all elements are informed. In same line that function arguments can have default values.

The following is for example allowed:


array<int> hoge = { 1,,,,5 };

This would create an array of 5 elements, but only the first and last element has a specified value.

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