Archive 17/01/2023.

Getting return values from script instance functions

Liichi

Hi, im using “Execute” method to call a function from another script, but i don’t know how to get return values. Someone knows?
PS: im using angelscript.

jmiller

Hi Liichi,

Perhaps your answer is in this thread:

*edit: Oops, I misread your issue.

Liichi

The problem it’s that asIScriptContext is not exposed to angelscript :confused:

KonstantTom

Hi! In my project I solved this problem using out reference as function parameter.

// AngelScript side.
void Process (/*other parameters*/, /*OutputType*/ &out output)
{
    /*...*/
    output = /*execution  result*/;
}
// C++ side.
Urho3D::VariantVector executionParameters;
/* ... push other parameters ...  then push our output object.*/
executionParameters.Push (Urho3D::Variant (/*create object for output*/));
// Then execute.
/*scriptInstance*/->Execute (functionDecl, executionParameters);
// Then get our object from variant vector.
/*OutputType*/ executionResult = executionParameters.At (lastParamIndex).Get/*OutputType*/ ();

It sucessfully works with VariantMap output in my project.

Liichi

I tried it but not seem to work in script (im calling scriptInstance.execute from another script).
Now im using node vars to store return value and then read it from another script, but it would be better to be able to get the returns directly.

Sinoid

Return values aren’t what Angelscript or Lua are meant for.

If you need instant return values than you need something like TinyExpr.

Now im using node vars to store return value and then read it from another script, but it would be better to be able to get the returns directly.

So you have a sequencing problem? Please tell us more so we can help you.