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.