• Advertisement
Sign in to follow this  

Initialize object at declaration

This topic is 1794 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement