GameMonkey Script

Using gmMachine::RegisterTypeLibrary with gmUserObject
Page 1 of 1

Author:  mrbarrysoftware [ Wed Sep 26, 2012 10:09 pm ]
Post subject:  Using gmMachine::RegisterTypeLibrary with gmUserObject

The problem I'm having is that I don't know how to get the base-object from the type-function. For instance:

void Register_Overlay_InGamemonkey_VM( gmMachine *vm )
   static gmFunctionEntry overlayFuncs[] = {
      { "on_draw", Overlay_OnDraw, NULL },
      { "show", Overlay_Show, NULL },
      { "hide", Overlay_Hide, NULL },
      { "primitive", Overlay_Primitive, NULL }
   vm->RegisterTypeLibrary( vm->GetTypeId("Overlay"), overlayFuncs, 4 );

Here is the "show" code:

int GM_CDECL Overlay_Show(gmThread * a_thread )
   Overlay *ol = (Overlay *)a_thread->ThisUserCheckType( a_thread->GetMachine()->GetTypeId("Overlay") );
   if ( ol == NULL ) {
      GM_EXCEPTION_MSG( "Expected 'this' to be of user-type 'Overlay'" );
      return GM_EXCEPTION;
   return GM_OK;

Then in game monkey:

print("Beginning test"); // Displays properly (I have a print callback setup)
test = Bear.window.getOverlay("test"); // Returns a Overlay-typed variable; // Breaks the script
print( "test to see if the script has stopped or not" ); // Never gets displayed

There is no documentation on how to get the data stored in 'test' inside the 'show()' function.

Thanks for any help,

Author:  Greg [ Sat Sep 29, 2012 2:33 am ]
Post subject:  Re: Using gmMachine::RegisterTypeLibrary with gmUserObject

Exactly what error messages are you seeing?

If you print the result of 'test = Bear.window.getOverlay("test")'
eg. print("test=",test")
What is do you see? We expect to see a pointer to user type 'Overlay'.

I don't quite understand what 'the data stored in 'test' inside the 'show()'' means.
'test' should be a gmUserObject. From that you would be able to access type bound functions like the ones you show. (They look fine to me.) To access data members, operator Get/SetDot must be implemented as gmUserObjects have none built in.

Edit: If you're asking how to access the Overlay members inside function show() (native function Overlay_Show()), what is the value of 'Overlay *ol' ? Is it valid or null?

Author:  mrbarrysoftware [ Sat Sep 29, 2012 3:51 am ]
Post subject:  Re: Using gmMachine::RegisterTypeLibrary with gmUserObject

So I decided since I was already going insane, I walked my pop-can through my code, and realized that I did a mass copy/paste of my function assignments for one of my tables, and forgot to change the one that controls `Bear.window.overlay`

So oops, that was totally my mistake. :oops:


Author:  Greg [ Sat Sep 29, 2012 6:11 am ]
Post subject:  Re: Using gmMachine::RegisterTypeLibrary with gmUserObject

Glad to hear you have it sorted.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group