View Full Version : Weird format to:stringstream problem...

03 March 2009, 04:02 PM
Hey all,

I got a small problem here with my Maxscript in Max Design 2009 (actually its a really annyoing one).

I changed my exporter code, so that it don't use directly format to:<filestream> but instead uses a stringstream to buffer the data and write it at once to the disk.

The MaxScript Reference says that one can use the "format to:" function with all type of streams including a <StringStream> but actually I always get the following error:

Type error: to: requires character stream, got: StringStream

I looked around a while, but couldn't find anything useful on the net, maybe someone of you has an idea what can be wrong.

03 March 2009, 04:40 PM
I'm not sure about your problem, it would be easier to understand by reading the code causing the error. I got it in one case only: declaring a variable = StringStream without anything else. Anyway I put together some easy samples that may help you to figure out what's wrong.

ssBuffer = StringStream ""
format "Hello " to:ssBuffer

tempString = "World!"
format "%" temp to:ssBuffer

ssBuffer2 = (ssBuffer as String)
format " %" ssBuffer2 to:ssBuffer

seek ssBuffer 0
print (ssBuffer as String)

-- output: "Hello World! Hello World!"

- Enrico

03 March 2009, 04:47 PM
One case I run into which constitutes about 90% of this error is when I try to format a filestream or stringstream to a filestream or stringstream.

Here is what you have to do:

StringstreamVar = Stringstream ""
format "hello" to: stringstreamvar
FilestreamVar = createfile "C:\hello.temp"
Format (StringstringVar as string) to:FilestreamVar
close FilestreamVar.

03 March 2009, 04:56 PM
Thanks to both of you,

it was a very simple error actually.
I created the stream by using

ssBuffer = StringStream

instead of

ssBuffer = StringStream ""

now it seems to work as it should.

CGTalk Moderation
03 March 2009, 04:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.