using angelscript

Started by
0 comments, last by WitchLord 19 years, 3 months ago
just tried angelscript. cool stuff. i used the struct Obj in testexecutestring.cpp to test updating of variables. everything works fine if i do this: ---- C++ code ---- engine->RegisterGlobalProperty("Obj g_Obj", &g_Obj); ---- angel script ---- g_Obj.a = false; but when i changed to using pointer, it does not work anymore: ---- C++ code ---- engine->RegisterGlobalProperty("Obj *g_Obj", &g_Obj); ---- angel script ---- g_Obj->a = false; i got a "Access violation reading location" error. how to solve this problem because i am using a lot of pointers in my code.
Advertisement
If you want to register a pointer to an object to be used by the script you have two options:

Either:

// C++CObj *ptr;engine->RegisterGlobalProperty("Obj obj", ptr);// AngelScriptobj.a = false;


Or:

// C++CObj *ptr;engine->RegisterGlobalProperty("Obj *obj", &ptr);// AngelScriptobj->a = false;


Note that it in the second case you need to make sure that the variable holding the pointer lives as long as the script engine that you register it with does, otherwise the value of the pointer that the engine holds will change as the memory is reused.

Regards,
Andreas

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