Passing pointer to struct
Hi
I have the following
typedef struct
{
float posX;
float posY;
} _2dPoint;
typedef struct
{
_2dPoint pos;
float somethingelse;
float anotherThing;
} _wayPoint;
extern _wayPoint *waypoints;
waypoints = malloc(enough space to hold all the data)
Q: How do I pass the waypoints pointer to a script, so that within the script I can access:
waypoints.pos.posX
Thanks very much.
AngelScript doesn''t yet support the [] operator so I suggest you do the following:
Register this function as follows:
This will allow you to make the following statements in AngelScript:
__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library
_wayPoint *WayPoint(int index){ if( index < 0 || index >= maxWayPoints ) { GetActiveContext()->SetException("Out of bounds"); return 0; } return waypoints[index];}
Register this function as follows:
engine->RegisterGlobalFunction("waypoint &WayPoint(int index)", asFUNCTION(WayPoint), asCALL_CDECL);
This will allow you to make the following statements in AngelScript:
int n = 10;waypoint wp;wp = WayPoint(n);wp.pos.posX = WayPoint(n+1).pos.posX;wp.pos.posY = WayPoint(n+2).pos.posY;WayPoint(n) = wp;
__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library
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
Popular Topics
Advertisement