Unexpected behavior when registering a global property

Started by
2 comments, last by WitchLord 9 years, 5 months ago

I had a case where i registered a global property like this:


pEngine->RegisterGlobalProperty( "Schedule@ slIdleStand", slIdleStand );

slidleStand is a Schedule array like so: Schedule slidleStand[].
It implicitly converts to a Schedule*.

The script class is a reference type.

The behavior i didn't expect is that when using this global property, the address being passed into functions was incorrect.

Changing the declaration to "Schedule slIdleStand" fixed it.

Is this normal behavior, and if so, why? How would i register a handle to an object using this?

Advertisement

If your declaration is "Schedule @slIdleStand", i.e. you want the script to be able to reassign the handle to point to a different object, then the second argument must be a pointer to a pointer to a Schedule object, e.g.

static Schedule *g_slIdleStandHandle = &slidleStand[0];  // Declared globally so the address of the variable is valid while the engine is valid
pEngine->RegisterGlobalProperty( "Schedule@ slIdleStand", &g_slIdleStandHandle );

Unfortunately there is no way for AngelScript to see the difference between one pointer to another, otherwise I would make AngelScript return an error if the property is registered incorrectly.

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 see, so handles are always pointers to pointers then?

A handle is a pointer.

However, since you need want to register a property that is a handle, then you need to give the address of that handle, and not to the object it points to.

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

This topic is closed to new replies.

Advertisement