Printf for script
by Howard Dortch · in Torque Game Engine · 07/26/2007 (9:01 am) · 5 replies
Is there a printf for scripts?
I want to print a value with 2 decimal places in script.
I want to print a value with 2 decimal places in script.
#3
usage: echo(formatFloat("%.2f", %var));
07/26/2007 (12:11 pm)
I wrote these to get that job done:ConsoleFunction(formatInt , const char*, 3, 3, "formatInt(format, int)")
{
char* ret = Con::getReturnBuffer(64);
dSprintf(ret, 64, argv[1], dAtoi(argv[2]));
return ret;
}
ConsoleFunction(formatFloat , const char*, 3, 3, "formatFloat(format, float)")
{
char* ret = Con::getReturnBuffer(64);
dSprintf(ret, 64, argv[1], dAtof(argv[2]));
return ret;
}
ConsoleFunction(formatString, const char*, 3, 3, "formatString(format, string)")
{
char* ret = Con::getReturnBuffer(4096);
dSprintf(ret, 4096, argv[1], argv[2]);
return ret;
}usage: echo(formatFloat("%.2f", %var));
#4
07/26/2007 (12:11 pm)
Also fwiw, i put em in consoleFunctions.cc
#5
07/26/2007 (1:04 pm)
Thanks Orion I thought there might be that ability already in script, I was just about to do this.
Associate Anthony Rosenbaum