Anim8or Community

General Category => ASL Scripts => Topic started by: NickE on July 21, 2008, 10:46:59 pm

Title: PrinttoString file function
Post by: NickE on July 21, 2008, 10: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?
Title: Re: PrinttoString file function
Post by: BOB_I_Ts on July 22, 2008, 05: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 !
Title: Re: PrinttoString file function
Post by: NickE on July 22, 2008, 02:36:18 pm
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.

Title: Re: PrinttoString file function
Post by: Steve on July 25, 2008, 07: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!!!