[Closed] saving array down to disk
Hi.
I need to save an array of booleans in an external file that would let me open the max scene and run the script using the array directly without having to fill it first with the values (because of the time this task takes to complete) but by just loading the file containing the array as i would with a bitmap file.
if somebody could tell how to save the array for future use (and how to load it afterwards) i would be very grateful.
thanks.
Hi Grenadine,
you can save variables (including arrays) inside of MAX files by making them persistent does this help you? have a read in the MSX help.
J.
Hi j_man
Thanks for the piece of advice.
Gotta try but seems like a solution.
However an external file would be more handy because it would enable me to load in my max file a specified version of the array among several coming from different max scenes.
(by keeping a library of my different arrays on disk, instead of a bunch of heavy max files)
Heard it was possible but couldn’t make it from the Mxs examples.
Thanks J_man i’m sure it’ll make it for now.
Ok,
well basically you need to create a function to save your txt file:
myarr=#(1,2,3,4,5,6,7,8,9,0)
f=createfile "d:\ emp\\output.txt" -- this is the output directory for the text file
for s in myarr do format ((s as string)+",") to:f
close f
and then you need to create a function to re-construct the data from the text file when you load it again.
I just posted something else along these methods:
newarr =#()
f=openfile "d:\ emp\\output.txt"
while not eof f do
(
n =readdelimitedstring f ","
append newarr n
)
format " %
" n
Cheers,
J.
Works perfectly. this is exactly what i needed.
Thank you J, both of your tips helped a lot.
Cheers
newarr =#()
f=openfile "d:\ emp\\output.txt"
while not eof f do
(
append newarr [b](readvalue f)[/b]
)
format " %
" n
This method might be more appropriate in your case since it will read the values back in as integers just like you had in the original array.
- Martijn