Deyja is correct. (Thanks for helping out, Deyja!)
If you had added some error checking you might have been able to discover this yourself.
Here are a few suggestions:
1. Always verify that the functionID is valid. Also verify the return code from Execute(). Both of these error checks would have told you that something was wrong in your program.
Execute() will return a negative value if it wasn't able to execute anything, e.g. if the context isn't prepared correctly. Otherwise it will return one of the asEXECUTION_???? codes, that you'll find in the documentation or angelscript.h.
int functionID = engine->GetFunctionIDByDecl("module", "void DoSomething()");if( functionID < 0 ){ cout << "Couldn't find the function" << endl;}else{ // Execute the script function context->Prepare(functionID); int r = context->Execute(); if( r != asEXECUTION_FINISHED ) { cout << "Execution didn't finish normally. Please verify why that is. (" << r << ")" << endl; }}
2. When registering functions and properties with the engine I always add an assert afterwards to verify the return code. I only use an assert, because if it works in debug mode, it will work in release mode as well.
r = engine->RegisterGlobalProperty("int counter", &counter); assert( r >= 0 );r = engine->RegisterGlobalFunction("void Test()", asFUNCTION(Test), asCALL_CDECL); assert( r >= 0 );
3. When calling Build() use the asIOutputStream, to receive compiler messages. Also, if the build fails, the return code will be negative, however you will catch the build error when trying to get the function ID later on so it is not necessary to check for this here.
class COutputStream : public asIOutputStream{public: void Write(const char *text) { cout << text; }};COutputStream out;engine->Build("module", &out);
One last thing. You never release the engine in your code, causing a memory leak. Not something terribly important since the application exits anyway, but I just thought I'd point it out.
I hope you will like AngelScript, and don't hesitate to let me know if you think it can be improved in anyway. [smile]
Regards,
Andreas