Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Initialize object at declaration


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 ikam   Members   -  Reputation: 134

Like
0Likes
Like

Posted 23 February 2013 - 12:22 PM

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



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 23 February 2013 - 12:46 PM

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

#3 ikam   Members   -  Reputation: 134

Like
0Likes
Like

Posted 23 February 2013 - 11:36 PM

thanks very much smile.png

It works and It's exactly what I need.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS