API Question CELBODY2::GetParent()

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
I need to know the parent body of a celestial body.

I call CELBODY2::GetParent() from inside CELBODY2::clbkInit(FILEHANDLE cfg), but I always get a NULL pointer.

Please, could somebody help me?
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
508
Points
113
I would guess, that at the point (in time) "clbkInit" is called, that relation (Parent->Child) is not yet given.
You might check if "GetParent()" suceedes when e.g. called in "clbkAtmParam" (for example).
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
I didn't think that was the problem, but it's perfectly reasonable.

I moved the call to GetParent() and now it works.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
508
Points
113
Thanks for the feedback!
Maybe martins should add that information to the API docs.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,885
Reaction score
2,139
Points
203
Location
between the planets
Maybe martins should add that information to the API docs.

It's a known phenomenon that many functions (especially getters) don't perform as expected in clbkInit() resp. clbkSetClassCaps() / clbkLoadState() for vessels. There would be a lot to update. As a general rule of thumb, use SetClassCaps/Init for initialising static and default properties, loadstate for setting properties from the scenario file, and PostCreation to set states and anything left over (In some cases it is even advisable to carry over data from the scenario file and set them in PostCreation if they refer to a VESSEL3 native property). That is assuming the CELLBODY class has an analogue to PostCreation, but I would assume so. Never worked with it so far.
 
Top