Forums > Javascript

creating files problem in a standalone

January 21, 2008 | 6:01 pm

Hi,

I’m using the code below to save data in a file. This works well as long as I’m working with Max, but it doesn’t write in the file when I run the standalone program. I am able to read the file though.
In the code below, I’m posting a message if the system cannot open the file. I never get this message on the console, so I presume that the standalone can create or open the file, but maybe only in read mode? In fact, the data stored in these file can be read but cannot be changed in the standalone version of my program.

Thanks for your help.

Jean-Baptiste

function save(n)
{
var cpt = n%8;

var f = new File("bkp"+cpt,"readwrite");
var s = new Array(4);

if (f.isopen)
{
f.writefloat32(Math.PI);

f.close();

post("nThe file ",f.foldername,f.filename,"has beed saved");

} else {
post("could not create file: ",f , "n");
}

}


January 21, 2008 | 11:27 pm

On 21 janv. 08, at 19:01, Jean-Baptiste Thiebaut wrote:

> Hi,
>
> I’m using the code below to save data in a file. This works well as
> long as I’m working with Max, but it doesn’t write in the file when
> I run the standalone program. I am able to read the file though.
> In the code below, I’m posting a message if the system cannot open
> the file. I never get this message on the console, so I presume that
> the standalone can create or open the file, but maybe only in read
> mode? In fact, the data stored in these file can be read but cannot
> be changed in the standalone version of my program.

Hi,

The save() method is called when you save the patch, which, AFAIK, is
something which is not possible in a standalone. You may have to use
other strategy to trigger the writing mechanism of your file.

HTH,
ej


January 21, 2008 | 11:46 pm

Hey Emmanuel,

thanks for your answer.
Is there a save() method called when the program is closed? I just called this function "save" without guessing it could be a reserved word. I’ll try to change the name. I’ll let you know if it works.

JB


January 22, 2008 | 12:03 am

On 22 janv. 08, at 00:46, Jean-Baptiste Thiebaut wrote:

> Hey Emmanuel,
>
> thanks for your answer.
> Is there a save() method called when the program is closed? I just
> called this function "save" without guessing it could be a reserved
> word. I’ll try to change the name. I’ll let you know if it works.

Nope, it’s called when the patch is saved (p11 in JavascriptInMax.pdf).

Cheers,
ej


January 22, 2008 | 7:55 am

I changed the name of my function to "_save()" and the same problem occurs: the data can not be saved when the function is called from a standalone, while it works when it is called from Max.

I’m not too sure where the file would be created though. When the function is called from Max, the file is created in the same folder that contains the JS file. Within a standalone in Mac OS, where should the file be created anyway?


January 22, 2008 | 8:15 am

On 22 janv. 08, at 08:55, Jean-Baptiste Thiebaut wrote:

> I changed the name of my function to "_save()" and the same problem
> occurs: the data can not be saved when the function is called from a
> standalone, while it works when it is called from Max.
>
> I’m not too sure where the file would be created though. When the
> function is called from Max, the file is created in the same folder
> that contains the JS file. Within a standalone in Mac OS, where
> should the file be created anyway?

Can you try to provide an absoulte path to your File object? You may
use the max.apppath property to find where the standalone is.

ej


January 22, 2008 | 12:42 pm

Quote: Emmanuel Jourdan wrote on Tue, 22 January 2008 08:15
—————————————————-
> On 22 janv. 08, at 08:55, Jean-Baptiste Thiebaut wrote:
>
> > I changed the name of my function to "_save()" and the same problem
> > occurs: the data can not be saved when the function is called from a
> > standalone, while it works when it is called from Max.
> >
> > I’m not too sure where the file would be created though. When the
> > function is called from Max, the file is created in the same folder
> > that contains the JS file. Within a standalone in Mac OS, where
> > should the file be created anyway?
>
> Can you try to provide an absoulte path to your File object? You may
> use the max.apppath property to find where the standalone is.
>
> ej
>
>
—————————————————-

Trying this, I had another unexpected error:

function _save(n)
{

var f = new File("bkp","readwrite");
f.foldername = max.apppath; //this makes the both max and the standalone crash
}


January 22, 2008 | 12:47 pm

> —————————————————-
>
> Trying this, I had another unexpected error:
>
> function _save(n)
> {
>
> var f = new File("bkp","readwrite");
> f.foldername = max.apppath; //this makes the both max and the standalone crash
> }

my mistake. f.foldername has no set method…


January 29, 2008 | 5:58 pm

Hi,

I’m a bit desperate to get this working.

The function below save a file while I’m running Max but doesn’t when I’m running the standalone. But, more strange, while running the standalone, the file is opened (I have a message on the console) but the file is not written on the disk. I’ve checked everywhere and the file is not created, although the condition "f.isopen" is satisfied.

function _save(n)
{

var f = new File("bkp","readwrite");

if (f.isopen)
{
f.writefloat32(3.14159);
f.close();
post("nthe file has been saved");

}
else
post("could not create file: ",f , "n");

}

Any idea?

Thanks
JB


January 29, 2008 | 7:02 pm

It seems that the problem is elsewhere. Please don’t waste your time on this, I’ll let you know what I’ve done wrong :)


January 30, 2008 | 8:42 am

Hi,

I finally solved the problem. We apparently can’t modify a file that has been included in the standalone package.

To give you an example, I have been including a number of files, called "bkp0", "bkp1", and so on, in my standalone so the files could be used by the programs. My app allows to modify these files. When these are stored within the program package I can’t modify them, so I guess that it forces the file to be opened as "read" instead of "readwrite", for instance.

The solution was to remove the files before creating the standalone so that they would not be included, then add them manually at the same level as the application. The files can then be modified.

Cool. For those who used my program Pompiloop and reported about this bug, this is now fixed and should be online sometime today at http://www.pompiloop.com/

Jean-Baptiste


January 30, 2008 | 10:15 am

On 30 janv. 08, at 09:42, Jean-Baptiste Thiebaut wrote:

>
> Hi,
>
> I finally solved the problem. We apparently can’t modify a file that
> has been included in the standalone package.
>
> To give you an example, I have been including a number of files,
> called "bkp0", "bkp1", and so on, in my standalone so the files
> could be used by the programs. My app allows to modify these files.
> When these are stored within the program package I can’t modify
> them, so I guess that it forces the file to be opened as "read"
> instead of "readwrite", for instance.
>
> The solution was to remove the files before creating the standalone
> so that they would not be included, then add them manually at the
> same level as the application. The files can then be modified.

I can confirm the behavior. Thanks for the report.

ej


Viewing 12 posts - 1 through 12 (of 12 total)