Can you write a 'type' to file?

BlitzPlus Forums/BlitzPlus Programming/Can you write a 'type' to file?

Dan60(Posted 2004) [#1]
Can you write a 'type' to file?

In C and VB you can write struct to file. Can't seem to be able to do that in blitzbasic.


Miracle(Posted 2004) [#2]
Nope, you'll have to "take the type apart" and save all its elements individually. Then you have to load the elements back in order to recreate the types. It's a bit of a hassle.


Binary_Moon(Posted 2004) [#3]
Nope, you'll have to "take the type apart" and ...


or... Yes. just use

writeline file,str(type.mytype)


decoding it once saved is your problem - unfortunately there isn't an easy 'loadType' command


Hotcakes(Posted 2004) [#4]
I take it something like
ReadLine file,Val(type.mytype)
doesn't work as nicely as Str$ does ;]


Miracle(Posted 2004) [#5]
Wow, that does work. My bad. Doesn't look like you can save Blitz arrays this way (it transliterates them as "???"), but everything else works fine.


Floyd(Posted 2004) [#6]
You can save the data with Str(), but it is more trouble that it is worth.
There is no provision for reading it back.
Also, floating point values saved as strings get rounded to six digits.
So they will usually not read back exactly.

The best way to read and write type objects is to create your own functions.


Zakk(Posted 2009) [#7]
I tried the Str() method with a type that had pointers as fields and it didn't work exactly as planned... just wrote [OBJECT] a lot.


Sauer(Posted 2009) [#8]
I've never gotten Blitz to print out a type successfully either; I think your best bet is to write the parts out individually.


Beaker(Posted 2009) [#9]
Or use BlitzMax. ;)


emmv75(Posted 2009) [#10]
i am telling you that reading is not as easy as writing

Zakk's post (Posted 1 day ago) #7

I tried the Str() method with a type that had pointers as fields and it didn't work exactly as planned... just wrote [OBJECT] a lot.

--------------------
<XtiaeN>: i wear my rollerblades while i hack games, for quick getaways


Sauer(Posted 2009) [#11]
I'm officially confused now.