[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sc-users] sorry wrong topic - DATA FILES
I write archives....
you can
[2,3,4,5,6].writeArchive("arc");
a=Object.readArchive("arc");
also find it useful that you can archive instances....
//class code put into SCClassLibrary
<x-tad-smaller>Test
{
var <>a,<>b;
*new{^super.new.a_(2).b_(5)}
}
//
c=Test.new
[c.a,c.b]
c.writeArchive("test")
d=Object.readArchive("test")
[d.a,d.b]
this way you can have nicely named, automatically savable and organized data structures</x-tad-smaller>
<x-tad-smaller>
Test
{
var <>a,<>b,<>path;
*new{^super.new.a_(2).b_(5).path_("test")}
save{this.writeArchive(path)}
}</x-tad-smaller>
<x-tad-smaller>c=Test.new
[c.a,c.b]
c.save
d=Object.readArchive("test")
[d.a,d.b]
</x-tad-smaller>
dig into class writing, it is the most transparent and readable it can get (for me)
cheerz
On Dec 28, 2004, at 5:31 PM, pb wrote:
Hi,
I'm having problems with cottle's data file example. I found a way to
retrieve the array back, but I'm a SC beginner then I probably went to the
most stupid and difficult way to do it. Anyone knows how to fix this
problem ?
Thanks! pb.
// cottle's example:
//writing array to data file
var fp, data;
fp = File("TestInt", "w"
data = [65, 66, 67, 68, 69, 70, 71];
data.do({arg eachInt; fp.putInt16(eachInt)});
fp.close;
//works fine
//getting the array back from file and placing the the variable data
var fp, data;
fp = File("TestInt", "r"); //open a file
data = fp.getAllInt16; //read all as Int array
data.postln;
fp.close;
// SC tells me Message " 'readAllInt16' not understood."
// my way
var fp, data;
fp = File("TestInt", "r"); //open a file
data= Array.fill(7,{ fp.getAllInt16 });
data.postln;
fp.close;
_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users