Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  


Ian Ross has just released a book on Anim8or. It's perect for a beginner and a good reference for experienced users. It contains detailed chapters on every aspect, with many examples. Get your own copy here: "Anim8or Tutorial Book"

Author Topic: PrinttoString file function  (Read 9674 times)


  • Full Member
  • ***
  • Posts: 166
    • View Profile
PrinttoString file function
« on: July 21, 2008, 06:46:59 pm »

I cannot get the PrinttoString file function to work.  The following test script:
Code: [Select]
string $fname;
file $output;


string $tostring;
int $i;


$output.PrintToString($tostring,"test: %d",$i);


Gives "undefined member reference 'PrintToString'" error.  Interestingly, the line:
Code: [Select]
PrintToString($tostring,"test: %d",$i);does not give an error, but returns an empty string.

Your thoughts?


  • Full Member
  • ***
  • Posts: 157
    • View Profile
    • Anim8rOrg
Re: PrinttoString file function
« Reply #1 on: July 22, 2008, 01:16:06 am »

been while since tried scripts but $tostring has to have an input befor it can output print !
 somthing like $tostring = $fname ; is missing
only time i used strings was umm ...
this one export_materialv1.a8s maybe helpful reference !
« Last Edit: July 22, 2008, 01:25:02 am by BOB_I_Ts »


  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: PrinttoString file function
« Reply #2 on: July 22, 2008, 10:36:18 am »

Thank you for your input, but you have misread my post.  According to the updated scripting manual (after the 0.97b release), "PrintToString" is a new function that works similarly to the C function sprintf.  It is supposed to put the results of the formatting and variables into the string variable. 

In ASL, PrintToString is a member function of the "file" type.  My post above is pointing out that it returns the "undefined member reference" error when used as a member function.  Further, that it does NOT return an error when used by itself, but also does not return the string variable loaded with any result.

Therefore, I am either using the function incorrectly in some way, or there is a bug.



  • Administrator
  • Hero Member
  • *****
  • Posts: 2122
    • View Profile
Re: PrinttoString file function
« Reply #3 on: July 25, 2008, 03:24:56 am »

PrintToString does not write to it's first argument.  The first argument is the format.  The documentation is incorrect.  It *used* to be like that but I changed it and forgot to fix teh documentation.

If you use it like this:

string $foo;
int $i;
$i = 10;
$foo = PrintToString("$i = %d", $i);

then $foo will have the value "$i = 10" afterwards.

Here's a sample full shader:
/* print_to_string.txt */

file $console;
string $str, $str2;
int $ii;

$"$console", "w");

$console.print("I'm writing to the console!\n");
$console.print("The square root of 2 is %12.8f\n", sqrt(2.0));

$str = PrintToString("this is a string");
$console.print("The value of the string is \"%s\".\n", $str);

$str2 = PrintToString("this is a float %6.3f, an int %d, and a string '%s'", 1.2
34, 777, $str);
$console.print("The value of the string is \"%s\".\n", $str2);

Sorry about the confusion!!!