# consts in switch and string parameter for entry function

## Recommended Posts

Jedive    120
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?

##### Share on other sites
WitchLord    4678
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

##### Share on other sites
Jedive    120
Thanks WitchLord!

Both things worked perfectly :D

##### Share on other sites
Deyja    920
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");