Sorry if this has been asked before, I could not find a way to search only in the AngelScript section of GameDev forums. I used AngelScript in a project many years ago, and now I have come back to it, although I am pretty new and unexperienced with it.
I have embeded AngelScript in my application, with the array and stdstring addons and a simple Print function, and I have made one small test:
void Main() {
string[] arr;
arr.insertLast("Hello");
arr.insertLast(" ");
arr.insertLast("world!");
arr.insertLast("\n");
for ( uint32 i = 0; i < arr.length; i++ )
Print(arr[i]);
}
This example compiles without any issues and prints "Hello world!" as expected. The problem comes when instead of the "string" class, I create an array with a class defined in the scripts. To see this problem, let's change the code to this:
class S {
S(string s) {
this.s = s;
}
string s;
}
void Main() {
S[] arr;
arr.insertLast(S("Hello"));
arr.insertLast(S(" "));
arr.insertLast(S("world!"));
arr.insertLast(S("\n"));
for ( uint32 i = 0; i < arr.length; i++ )
Print(arr[i].s);
}
The compiler reports the following messages:
hello.as (9, 1) INFO: Compiling void Main()
hello.as (11, 5) WARNING: 'arr' is not initialized.
hello.as (11, 5) ERROR: Illegal operation on '<unknown>'
hello.as (12, 5) ERROR: Illegal operation on '<unknown>'
hello.as (13, 5) ERROR: Illegal operation on '<unknown>'
hello.as (14, 5) ERROR: Illegal operation on '<unknown>'
hello.as (16, 29) ERROR: 'length' is not a member of '<unknown>'
hello.as (17, 12) ERROR: Type '<unknown>' doesn't support the indexing operator
If I change the declaration of the array from "S[] arr;" to "array<S> arr;" it also gives the following error:
hello.as (10, 8) ERROR: Can't instanciate template 'array' with subtype 'S'
May someone with more experience tell me what I am doing wrong?
Thanks in advance, and congratulations Andreas for creating such a nice and powerful scripting language.