🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

consts in switch and string parameter for entry function

Started by
2 comments, last by Deyja 18 years, 3 months ago
I am embedding AngelScript into my application. The host application calls the main() function into the script. I have no problems passing the int and float parameters to it with asIScriptContext::SetArgDWord() and asIScriptContext::SetArgFloat(), but... how do I pass a string parameter to the main function? The other question: I need to export some defines to the scripts. As AngelScript do not supports them, what I am doing is exporting constants which hold the value (const int EV_INIT = 1, const int EV_FRAME = 2, etc). They do the job, but the problem is that they cannot be used in a switch loop. Do you know any solution for this?
Advertisement
You'll use the method SetArgObject() to pass the string to the script function.

ctx->Prepare(funcId);asCScriptString str("my string");ctx->SetArgObject(0, &str);ctx->Execute();


How are you exporting the constants, with RegisterGlobalProperty()? If the script compiler is to use a constant in a switch case the constant must have been declared in the script. Thus, my suggestion for exporting constants from the application to scripts is to construct a script section and add it to the module together with the real script.

const char *constants = "const int a = 1; const float pi = 3.14f;";engine->AddScriptSection("module", "constants", constants, strlen(constants), 0, false);engine->AddScriptSection("module", "the script", script, strlen(script), 0, false);engine->Build("module");


I will implement a way to register constants and enums directly with the engine, but it has quite low priority at the moment since the above works.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks WitchLord!

Both things worked perfectly :D
If you happen to use the preprocessor available on the addon page, you can #define constants. They don't need to be in the script file - theres a feature aimed specifically at this sort of thing.

Preprocessor::define("SOME_CONSTANT SOME_VALUE");

This topic is closed to new replies.

Advertisement