Is the any way to catch FileSaveAs error?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Is the any way to catch FileSaveAs error?

Post by strider2000 »

Is there any way to programmatically catch a FileSaveAs error?

The situation I have is that I'm using the NLD script and write to a file. I open the saved file. If I write again to that same file, while it's open it can hose my original file. Yes, there's an easy work around, don't do that :o, but I'd like to catch the FileSaveAs error (ie it throws a dialog if you just try FileSaveAs) I'd also like to catch if the file already exists to avoid accidentally overwriting a file. However, FileSaveAs returns void :o

Thanks for any help.
User avatar
hayasidist
Posts: 3509
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Is the any way to catch FileSaveAs error?

Post by hayasidist »

(sorry, don't know what the "NLD script" is) do you need to use the script interface file routines for this? LUA has file handling routines that will trap errors.

(I use LM.GUI.SaveFile to get the path name, then the lua io.xxx and file:xxx routines - http://www.lua.org/manual/5.2/manual.html#6.8 - once I've got the desired filename - e.g. as in this: http://www.kelleytown.com/forum/animato ... IC_ID=1431)
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Is the any way to catch FileSaveAs error?

Post by strider2000 »

Sorry, for the confusion. The NLD script is the No Limits Designer script by Mike Kelly. It's calling the script Interface routine. You bring up a good point I can check out the standard lua file handling and your link. Thanks :)
User avatar
synthsin75
Posts: 9968
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Is the any way to catch FileSaveAs error?

Post by synthsin75 »

At least on Windows, moho:FileSaveAs() just uses to OS dialog, so the OS should notify you if overwriting.

You can see if a file exists using:

local test = io.open(path, "rb")
If (test) then
--the file exists
io.close(test)
end

Make sure to close the file (io.close), if it exists.

I think if you save to an open file you typically need to reopen the file to see the changes.
User avatar
hayasidist
Posts: 3509
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Is the any way to catch FileSaveAs error?

Post by hayasidist »

strider2000 wrote:Sorry, for the confusion. The NLD script is the No Limits Designer script by Mike Kelly. It's calling the script Interface routine.
:oops: should have thought of that!!! (just didn't make the connection in the context of you seeming to want to update a script)
Post Reply