Jump to content
  • Advertisement
Sign in to follow this  

Some questions about Game Monkey Script

This topic is 2802 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

Hi anybody! I'm writing game engine for 3 years. It supports audio, physics. Now I started to use scripting languages to write logic for game.
First I checked Lua scripting language. But it has a bug when I connecting it to my engine, for example, I cann't send data from engine to script language.
I'm used "lua_pushnumber(ls, value);" for send double value but by calling 'io.write' I getting "0". So I'd be happy if someone answers me about it and what is wrong with it.

But when I collided with Game Monkey Script I started to like it. But there some problems that I cann't solve them by myself. So, the questions are:
QUESTION1. I have a problem with memory leaks when I'm using "a_operands[].SetUser", "a_thread->PushNewUser". How to delete the object from the stack? Can I setup constructor/destructor for that types of variables? If yes how I can do that? The part of code that works with GM looks like this:
//For example my types here is GM_VEC3, GM_CONTROLLER
void GM_CDECL ControllerGetDot(gmThread * a_thread, gmVariable * a_operands)
GM_ASSERT(a_operands[0].m_type == GM_CONTROLLER);
gmControllerStruct* cs = (gmControllerStruct*) ((gmUserObject*)GM_OBJECT(a_operands[0].m_value.m_ref))->m_user;

GM_ASSERT(a_operands[1].m_type == GM_STRING);
gmStringObject* stringObj = (gmStringObject*)GM_OBJECT(a_operands[1].m_value.m_ref);
const char* cstr = stringObj->GetString();

vec3 v = GetCharacterPos(cs->controller_Handle);
cs->position = v;
//it initalized here:
// m - gmMachine
GM_VEC3 = m.CreateUserType("vec3");
GM_CONTROLLER = m.CreateUserType("VController");
m.RegisterTypeOperator(GM_VEC3, O_GETDOT, 0, vec3GetDot);
m.RegisterTypeOperator(GM_VEC3, O_SETDOT, 0, vec3SetDot);
m.RegisterTypeOperator(GM_CONTROLLER, O_GETDOT, 0, ControllerGetDot);
m.RegisterTypeOperator(GM_CONTROLLER, O_SETDOT, 0, ControllerSetDot);
// that's all what I do for registering them. Yes I'm using pointers of "vec3","VController" that allocated by engine. And I'm glad to know how to use it for temp calculation.
QUESTION2: Scripts that I'm using can be called by triggers that exist in engine. So, there are many script files. How can I just to compile all codes (not execute them) but use it after some time later (where gmMachine is a global variable)?

Thanks for them who paid attention to my thread;)

Share this post

Link to post
Share on other sites
Hello guys again! I have found an answer of QUESTION2: "How can I just to compile all codes (not execute them) but use it after some time later (where gmMachine is a global variable)?"... gmMachine contains "CompileToFunction(...)" and "ExecuteFunction(...)" to work out.
But QUESTION1 is still a big problem for me. Does anyone use OOP objects to Game Monkey Script in C++ applications?

[Edited by - FXACE on November 12, 2010 10:00:04 AM]

Share this post

Link to post
Share on other sites
GameMonkey uses a garbage collector. You define a callback for the user type that will be executed when GameMonkey determines this object should be freed.

Look at gmMachine::RegisterUserCallbacks()

This is how you define the destructor callback that GameMonkey calls when this object should be deleted. You can also define the trace callback, so if your user type is using other objects, it can tell the garbage collector that this object is in use.


A constructor can be made by simply defining a global function. If you have a user type called "Vector" than you can make a global function called "Vector" which returns a new Vector object. It would look like this in GM script

myVector = Vector(32, 32);

GameMonkey is a very good scripting engine but i suggest you visit their forums http://www.somedude.net/gamemonkey/forum they will answer your questions.

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!