Anim8or Community
General Category => ASL Scripts => Topic started by: NickE on July 21, 2008, 06:46:59 pm
-
Steve,
I cannot get the PrinttoString file function to work. The following test script:
string $fname;
file $output;
$fname="$console";
$output.open($fname,"w");
string $tostring;
int $i;
$i=10;
$output.PrintToString($tostring,"test: %d",$i);
$output.print("%s\n",$tostring);
$output.close;
Gives "undefined member reference 'PrintToString'" error. Interestingly, the line:
PrintToString($tostring,"test: %d",$i);
does not give an error, but returns an empty string.
Your thoughts?
-
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 (http://homepage.ntlworld.com/w.watson3/main/files/export_materialv1.a8s) maybe helpful reference !
-
Bob,
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.
-
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.open("$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);
$console.close();
---------------------------------
Sorry about the confusion!!!