Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

An update to Anim8or, v1.00b, is available with a few bug fixes. Get your copy HERE. See the "ReadMe" file for details.

Author Topic: PrinttoString file function  (Read 4240 times)

NickE

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

Steve,
I cannot get the PrinttoString file function to work.  The following test script:
Code: [Select]
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:
Code: [Select]
PrintToString($tostring,"test: %d",$i);does not give an error, but returns an empty string.

Your thoughts?
Logged

BOB_I_Ts

  • Full Member
  • ***
  • Posts: 155
    • View Profile
    • Anim8rOrg
Re: PrinttoString file function
« Reply #1 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 !
« Last Edit: July 22, 2008, 05:25:02 am by BOB_I_Ts »
Logged

NickE

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

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.

Logged

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 1532
    • View Profile
Re: PrinttoString file function
« Reply #3 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.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!!!
Logged