Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

using angelscript


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 iram   Members   -  Reputation: 122

Like
0Likes
Like

Posted 20 December 2004 - 01:29 AM

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.

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3443

Like
0Likes
Like

Posted 20 December 2004 - 04:15 AM

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
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS