Game Development Community

Functions returning gibberish

by Michigan State University (#0021 · in Torque Game Engine · 06/09/2006 (10:25 am) · 3 replies

I've created a function by editing the engine that should return a const char* to TorqueScript.

It checks out when printed in the command window using the debug version, however, when it returns from the C++ side of things into TorqueScript, the TorqueScript variable is all gibberish, namely a bunch of those unknown character boxes. Any thoughts as to why this might be?

#1
06/09/2006 (10:29 am)
Post the source ?
#2
06/09/2006 (11:05 am)
Sorry, here's what's up:

function GuiMLTextCtrl::reload(%this, %obj)
{
    echo("Reload was called.");
    %this.setValue("");
    readDialogFile(%obj.dialogFile);
    
    %text = getFirstQuestionText();  // this line here.
    echo(%text);
    %this.setValue(%text);
    %this.forceReflow();
}

//corresponding to this function
ConsoleFunction(getFirstQuestionText, const char*, 1, 1, "getFirstQuestionText()")
{
	 FirstQuestionText = (ToTorqueConversation.getSetDlg(0).getQuestionText()).c_str();
	 return FirstQuestionText; 
}
#3
06/09/2006 (11:13 am)
Pretty sure you need to use a return buffer

ex:
myText = "test";
char* ret = Con::getReturnBuffer( 256 );
dSprintf( ret, sizeof(ret), "%s", myText );
return ret;