Page 1 of 1
Is the any way to catch FileSaveAs error?
Posted: Sat Aug 06, 2016 8:23 pm
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

, 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
Thanks for any help.
Re: Is the any way to catch FileSaveAs error?
Posted: Sun Aug 07, 2016 2:32 am
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)
Re: Is the any way to catch FileSaveAs error?
Posted: Sun Aug 07, 2016 9:45 am
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

Re: Is the any way to catch FileSaveAs error?
Posted: Sun Aug 07, 2016 10:07 am
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.
Re: Is the any way to catch FileSaveAs error?
Posted: Sun Aug 07, 2016 11:53 am
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.

should have thought of that!!! (just didn't make the connection in the context of you seeming to want to update a script)