Game Development Community

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.

#1
07/26/2007 (9:38 am)
Echo(%var);
#2
07/26/2007 (11:09 am)
%var = 1.234567890

I want 1.23

printf("%.2f",%var)
#3
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.