javascript file I/O….

May 19, 2006 at 8:52pm

javascript file I/O….

I am working on a library that will do generic file I/O.
I have been having a little trouble reading data back.
The following code snippet does not seem to return any
data.

function ReadInt()
{
if(f == null)
return;

var data ;
data = f.readint32(1);
if(data == null)
{
post(“No data”);
return;
}

post(“got data”);
outlet(0, data [0]);
}

It is says “got data” but nothing is sent out. The file position is
updated
each time I call ReaadInt(). Anyone have an idea what the problem
might be?

Anthony

#26071
May 22, 2006 at 3:07pm

Anybody have any ideas?

#77464
May 22, 2006 at 3:44pm

Hi,

I just check and it seems inconsistent (at least not coherent with
the documentation) because:

data = f.readint32(1) returns a number

and

data = f.readint32(2) returns an object (an Array)

so the following works here:

data = f.readint32(1);
if(data == undefined) {
post(“No data”);
return;
}
post(“got data”);
outlet(0, data);

Best,
ej

#77465
May 22, 2006 at 3:50pm

Actually the documention says that readint32
returns an array. So I assumed that f.readint32(1)
would return an array of size 1.

Anthony

#77466
May 22, 2006 at 3:53pm

On 22 mai 06, at 17:07, apalomba@austin.rr.com wrote:

> Anybody have any ideas?

What happens if you return a rather than a[0] ?

_____________________________
Patrick Delges

Centre de Recherches et de Formation Musicales de Wallonie asbl

http://users.skynet.be/crfmw/max

#77467
May 22, 2006 at 4:10pm

If you return data, as opposed to data[0], it works.
The documentation does not specify this behavior.
Thanks for your help.

Anthony

#77468
May 22, 2006 at 5:49pm

Another quick question, I am trying to write some
floats to a file. When I write any fractional numbers,
it looks like they are being converted into integers.

For example WriteFloat 0.5 is written to the file as
a zero. This is the function I am calling:

function WriteFloat(FloatData)
{
if(f == null)
return;

f.writefloat32(FloatData);
}

How can I get it to just write the data and not convert it?

Anthony

#77469
May 22, 2006 at 10:30pm

On 22-mai-06, at 18:10, apalomba@austin.rr.com wrote:

> If you return data, as opposed to data[0], it works.

:)
I don’t know why I proposed you to return “a” rather than “data”. Sorry!

p

#77470
May 22, 2006 at 10:40pm

On May 22, 2006, at 10:49 AM, apalomba@austin.rr.com wrote:

> Another quick question, I am trying to write some
> floats to a file. When I write any fractional numbers,
> it looks like they are being converted into integers.

I am unable to reproduce. Tthe following example demonstrates
writefloat32() and readfloat32() functions working under MaxMSP 4.5.7
on OS X.4.6. It could be that you are trying to exploit the byteorder
attribute, which is unfortunately broken in 4.5.7, but fixed in the
next version. However you haven’t provided us with enough detail to
examine your problem. As *always*, please provide a clear and simple
example which illustrates your problem with clear steps to reproduce,
and software and operating system information. Otherwise, there’s
less of a chance that you find the help you’re looking for.

function bang()
{
var f_out = new File(“./outputtest.bin”,”write”);

if (f_out.isopen) {
f_out.writefloat32(0.5);
f_out.writefloat32(17.93);
f_out.writefloat32(2.);
f_out.close();
}

var f_in = new File(“./outputtest.bin”,”read”);

if (f_in.isopen) {
post(“in[0]” + f_in.readfloat32(1) + “n”);
post(“in[1]” + f_in.readfloat32(1) + “n”);
post(“in[2]” + f_in.readfloat32(1) + “n”);
f_in.close();
}
}

-Joshua

#77471
May 23, 2006 at 3:28pm

Thanks for the example Joshua, as it turns out
the problem was bad message box formatting.

Thanks,
Anthony

#77472

You must be logged in to reply to this topic.