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`.
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`.
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
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