Advertisement

Initialize object at declaration

Started by February 23, 2013 06:22 PM
1 comment, last by fredakilla 11 years, 9 months ago

Hi

I'm new to angelscript and I can't do what I want.

I have a c++ struct :

struct float2
{
float x;
float y;
};

I register the object and property :

r = engine->RegisterObjectType("float2", sizeof(float2), asOBJ_VALUE | asOBJ_POD); assert( r >= 0 );
r = engine->RegisterObjectProperty("float2", "float x", asOFFSET(float2,x)); assert( r >= 0 );
r = engine->RegisterObjectProperty("float2", "float y", asOFFSET(float2,y)); assert( r >= 0 );

now in script I would like to declare a global variable of this struct with something like that, but it didn't work :

float2 myPoint = { 0.5f, 0.5f }; // initialize with lists didn't work

how I can init my var at declaration ? Do I need a constructor ?

thanks

You need to register the constructor.

I suggest you take a look at the scriptmathcomplex add-on that you'll find in the add_on/scriptmath/ folder. It registers a structure that is similar to your float2 struct.

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

Advertisement

thanks very much smile.png

It works and It's exactly what I need.

This topic is closed to new replies.

Advertisement