Sign in to follow this  
FXACE

Some questions about Game Monkey Script

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();

if(!stricmp("position",cstr))
{
vec3 v = GetCharacterPos(cs->controller_Handle);
cs->position = v;
a_operands[0].SetUser(a_thread->GetMachine(),&cs->position,GM_VEC3);
}
else
{
a_operands[0].Nullify();
}
}
//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.

http://www.gamedev.net/reference/programming/features/gmscript2/page12.asp

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this