GameMonkey Script

GameMonkey Script Forums
It is currently Tue Sep 07, 2010 11:40 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Greetings & quick questions
PostPosted: Sat Mar 29, 2008 6:02 am 
Offline

Joined: Sat Mar 29, 2008 5:07 am
Posts: 3
Greetings! I've very excited to join this GM community, I've been investigating scripting languages to integrate into a game engine I've been developing in my spare time. For my day job I'm a professional game engineer working on some high profile next-gen console games. We've integrated Lua into our next-gen engine so I've been treated to some of the delights and drawbacks of working with it. When I first discovered GameMonkey I was very impressed with what it appeared to offer. When I actually got around to giving it a test drive, I was amazed at how easy it was to integrate and bind with C code. I'm getting to the point where I am starting to really write scripts and get a hang of the language thus my need to register on the forums.

I've got a few questions to kick things off.

Q1 From C code is there an example or could someone show me an example of how to construct a table and push it as the return value?

Q2 I've had a view problems using strings in gmscripts. I've bound a function that pushes on input mappings in the scope "input". When I try to pass in a string like below it won't work and I get an error (don't remember what it said off hand).

Won't work:
Code:
input.PushInputMap("inputmaps/file.txt");

or

input.PushInputMap(filename = "Inputmaps/file.inputmap");

When I assign the string to the variable it is fine.
Works:
Code:
filename = "Inputmaps/file.inputmap";
input.PushInputMap(filename);

I know that print("hello"); works so whats up with the way I wanted to do it?

Q3 When I get runtime errors the callstack that gets printed out does not really have much information to help so I don't know which call or line look for problems at. Is there some sort of information I am not providing or processing. For example
I get this:
Code:
attempt to call non function type

unknown(0):

callstack..
    (0): __unkown
    (0): __unkown
    (0): __unkown

I'd really like to be able to display better information for tracking down that problem.

Q4 In file 'A.gm' I have a main loop from the scripts I then DoFile('B.gm') from 'A.gm' and declare a global table 'gX' with function Foo. I then call gX.Foo() from file 'A.gm' Ok so here is the question... If I DoFile('A.gm') and it starts a thread, when I call gX.Foo() does that mean Foo is running in the thread created for 'A.gm' or will it run in a thread that was created for 'B.gm'? More importantly if there is a runtime error (which will cause the thread to be killed correct?) will it kill my thread running 'A.gm'??? I'm asking because I'm worried about an error in a script used by my main script loop brining down all my script execution.

*wave* Gretz! + Thanks for your time!


Top
 Profile  
 
 Post subject: Re: Greetings & quick questions
PostPosted: Sat Mar 29, 2008 8:31 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 580
Welcome to the forum Impulse! I see you're not holding back on questions ;)
Impulse wrote:
Q1 From C code is there an example or could someone show me an example of how to construct a table and push it as the return value?

The code might look something like:
Code:
int SomeBoundFunc(gmThread * a_thread)
{
#if 0 // The short way
  gmTableObject* table = a_thread->PushNewTable(); // Push a new table
  table->Set( a_thread->GetMachine(), "Health", gmVariable(100.0f) ); // Fill table
#else // The long way
  gmMachine* machine = a_thread->GetMachine();

  // Disable GC as we may have floating objects (Paranoid, not currently necessary)
  bool gcEnabled = a_machine->IsGCEnabled();
  machine->EnableGC(false);

  // Create a new table
  gmTableObject* table = machine->AllocTableObject();

  // Fill table
  table->Set(a_thread->GetMachine(), "Health", gmVariable(100.0f) );

  // Push as return value
  a_thread->PushTable(table);

  // Re-enable GC (Paranoid, not currently necessary)
   machine->EnableGC(gcEnabled);
#endif
    return GM_OK;
}

There's the longest and shortest ways to do it off the top of my head. Note that disabling the GC around object allocations is currently not necessary as the GC does not run on each Alloc, but on Execute.
Quote:
Q2 I've had a view problems using strings in gmscripts. I've bound a function that pushes on input mappings in the scope "input". When I try to pass in a string like below it won't work and I get an error (don't remember what it said off hand).
Won't work:
Code:
input.PushInputMap("inputmaps/file.txt");
or
input.PushInputMap(filename = "Inputmaps/file.inputmap");

When I assign the string to the variable it is fine.
Works:
Code:
filename = "Inputmaps/file.inputmap";
input.PushInputMap(filename);

I know that print("hello"); works so whats up with the way I wanted to do it?

'input.PushInputMap(filename = "Inputmaps/file.inputmap");' This will not work because you cannot perfom an assignment in a function parameter list, or in a condition (unlike C). I am not sure why the first one 'input.PushInputMap("inputmaps/file.txt");' doesn't work. It looks fine to me. Could could try the alternate string delimters '`' (back dash) which ignore escape characters, so file paths are easier to work with, but that doesn't appear to be your issue. Perhaps someone else can spot a problem?
Quote:
Q3 When I get runtime errors the callstack that gets printed out does not really have much information to help so I don't know which call or line look for problems at. Is there some sort of information I am not providing or processing. For example
I get this:
Code:
attempt to call non function type
unknown(0):
callstack..
    (0): __unkown
    (0): __unkown
    (0): __unkown

I'd really like to be able to display better information for tracking down that problem.

Check that you have debug mode enabled with GM. If you do not have it enabled, your symbols will not be available. Also note that if you execute arbitrary string, you may lack filename or main function name.
Quote:
Q4 In file 'A.gm' I have a main loop from the scripts I then DoFile('B.gm') from 'A.gm' and declare a global table 'gX' with function Foo. I then call gX.Foo() from file 'A.gm' Ok so here is the question... If I DoFile('A.gm') and it starts a thread, when I call gX.Foo() does that mean Foo is running in the thread created for 'A.gm' or will it run in a thread that was created for 'B.gm'? More importantly if there is a runtime error (which will cause the thread to be killed correct?) will it kill my thread running 'A.gm'??? I'm asking because I'm worried about an error in a script used by my main script loop brining down all my script execution.
When you execute a gm script a new gmThread is created. Each time you call a script function from C, a new gmThread is created. If a gmThread fails, it will signal an exception and terminate that thread only.


Top
 Profile  
 
 Post subject: Re: Greetings & quick questions
PostPosted: Sat Mar 29, 2008 6:40 pm 
Offline
User avatar

Joined: Fri Jan 14, 2005 2:28 am
Posts: 434
Just to expand on what Greg said. gmMachine.SetDebugMode(true); will let GM hang on to debug information so you get useful callstacks and such.

Also, I think you will need to show what PushInputMap does for us to be able to possibly see what's going on.


Top
 Profile  
 
 Post subject: Re: Greetings & quick questions
PostPosted: Sat Mar 29, 2008 7:02 pm 
Offline

Joined: Sat Mar 29, 2008 5:07 am
Posts: 3
Thanks for the detailed answers! I'll try and figure what I've got going on with my issue in Question 2 and post some additional details if I still can't get it to work. Hopefully I should be able to get somewhere now that I know it should be working.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group