🎉 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!

array of object handles

Started by
12 comments, last by Rain Dog 18 years, 2 months ago
i have declared an object class myself. now i wanted to have an array of them, but cannot seems to be able to do it correctly. srObject@ Object_shape; //1 object srObject[] @list_of_Objects (100); //Error: only objects have contructors
Advertisement
It should be:

srObject@[] list_of_Objects(100);


You were actually declaring an object handle to and array of srObjects. [wink]

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

i tried that and it is throwing "Error : Expected data type"
i am using 2.5.0c

srObject@[] list_of_Objects(100);

It should work. I'll look into 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

I've been trying to reproduce your problem, and so far everything works as it should without any compiler errors. I can compile the following script without any problems:

string@[] c(10);


Perhaps it has to do with how you registered the srObject type. Can you show us how you've registered the type, including the behaviours? Also, can you show us the exact error messages that you're getting, as well as the script lines they refer to?

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


interesting.....

i tried to use your example, and string is registered per AS sample.

string@[] c(10); //this is a line 27


error message returned:
as (27, 13) : Error : Expected data type

Include the <vector> header file and use vector stl.

std::vector<srObject@> object_array;

Now resize the vector of objects to what ever size N you want.

object_array.resize(N);

Now you can use the vector just like an array.

object_array[0], object_array[1], object_array[2], .... , object_array[N]

Just make sure that you boundary check when you are tring to access an element in the vector/array.

Just make sure that you clear the vector, and free up the memory being used by the Objects in the vector/array.
And I am left wondering WTF that has to do with Angelscript...
I'm also wondering what the @ token means in C++. Is this something available in a newer version of C++ that I'm not aware of? [wink]

iram:

Which character is on the 13th column? Is it the c? Or @? Or []?

Are you declaring the array as a global variable? It could be that it would be parsed differently. I'll test that.

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

I think it's in C# or C++/CLI. I don't really know, I'm strictly a C++ guy.

This topic is closed to new replies.

Advertisement