Sign in to follow this  

using angelscript

This topic is 4776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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);

// AngelScript
obj.a = false;


Or:


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

// AngelScript
obj->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

Share this post


Link to post
Share on other sites
Sign in to follow this