Con::executef() not getting a return value
by Brian Tan · in iTorque 2D · 04/28/2009 (4:32 pm) · 8 replies
Hi,
I am making a new class by recompiling the engine and have come to an issue with Con::executef(). This is the code I have:
The echo prints out without any problems; I'm getting the value passed in by xBuffer and the resulting %val is calculated fine but the printf only shows output: <blank>
Am I missing something so that I can properly get the return value?
Thanks.
I am making a new class by recompiling the engine and have come to an issue with Con::executef(). This is the code I have:
// assume xBuffer is a char array with random numbers
const char* result = Con::executef( 2, testFunc, xBuffer );
Con::printf("output: %s", result);This is the script code that has that the "testFunc":function testFunc(%xx)
{
%val = mSin( %xx / 10 ) * 64 + 32;
echo("#" @ %xx SPC "-->" SPC %val);
return %val;
}The echo prints out without any problems; I'm getting the value passed in by xBuffer and the resulting %val is calculated fine but the printf only shows output: <blank>
Am I missing something so that I can properly get the return value?
Thanks.
#2
Did you ever figure out what was the cause of this? I'm hitting the exact same issue.
06/13/2009 (1:16 am)
Brian,Did you ever figure out what was the cause of this? I'm hitting the exact same issue.
#3
06/13/2009 (6:32 am)
Yes I have the exact same issue. Calling my custome console functions from script almost always return blank instead of hte value.
#4
I just skipped using that functionality for now until someone at GG takes a lfixes it.
06/15/2009 (9:18 am)
Nope. I have never figured it out.I just skipped using that functionality for now until someone at GG takes a lfixes it.
#5
use dAtoi
09/01/2009 (5:35 am)
try this use dAtoi
S32 result = dAtoi( Con::executef( 2, testFunc, xBuffer ) );
Con::printf("output: %d", result);
#6
09/01/2009 (7:26 am)
As BrianPark said - you need to convert the data to something the engine can read. :)
#7
09/01/2009 (11:03 am)
Actually he has it backwards. It's the return value TO script that wasn't working. It has since magically started working for me. No idea what was going on.
#8
A more "safe" fix would be to probably store that value into the static char "returnBuffer" like it does below in the function, but even that isn't guaranteed safe if you keep that pointer around and use it later, so just make sure to strcpy that return string into another string if you want to access it after the function returns. If you use it immediately (which you most probably will), then it should be fine as is.
09/02/2009 (4:26 am)
There is a bug in Torque that causes ScriptFunction types to not return their return value. We "fixed" it and sent it to Mich for the next version of iTGB, so it should be there, but for those of you who can't wait, this is the fix:const char *Namespace::Entry::execute(S32 argc, const char **argv, ExprEvalState *state)
{
if(mType == ScriptFunctionType)
{
if(mFunctionOffset) {
recursionCount++;
//pass in recursionCount, the number of times this entry has been called
const char * ret = mCode->exec(mFunctionOffset, argv[0], mNamespace, argc, argv, false, mPackage, recursionCount );
recursionCount--;
#ifdef _LUMA_FIX
return ret;
#endif //_LUMA_FIX
}
else
return "";
}
//rest of function here down here...A more "safe" fix would be to probably store that value into the static char "returnBuffer" like it does below in the function, but even that isn't guaranteed safe if you keep that pointer around and use it later, so just make sure to strcpy that return string into another string if you want to access it after the function returns. If you use it immediately (which you most probably will), then it should be fine as is.
Torque Owner Brian Tan