Skip to main content
GameDev.net gamedev.net
🔒 Locked

Passing pointer to struct

Started by Gibbon_99 Mar 30, 2004 at 9:28 PM 0 replies 1.6k views
Original Post
Gibbon_99
Gibbon_99
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.
WitchLord
WitchLord
AngelScript doesn''t yet support the [] operator so I suggest you do the following:


_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 - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.