View Single Post
Old 01-11-2019, 01:11 PM   #4
Human being with feelings
Join Date: Apr 2014
Posts: 2,836

Originally Posted by mespotine View Post
Could this be solved with a Main_SaveProject in the atexit-function? Or would this lead to other unforseen behavior?
I don't think that would work unfortunately. There's no way of telling whether the save as dialog was answered yes or no. In the case of No (do not save project) - my script does not want to be saving it's data.

And when simply closing the script manually (using the X) - we don't want to be saving the project - as the user may decide to discard the changes.

This is where the main problem lies - I have a system which uses a 'temporary' save file, and a 'non-temporary' one. I can detect when the user has hit save in the project when the script is running - triggering my script to save a 'non-temporary' save file.

But when the script is simply closed - it will save a 'temporary' save file - as at this point - there is no way of telling whether the user is going to save the project file or not. If they do not - then the user should be able to load the script with the correct version of the save data.

There's a lot more to it than just this - but I've found (or know) solutions to every problem so far except that if my script is running and the user closes Reaper - and then selects Yes to the save data dialog - my script saves the data - but the project cannot get updated with the correct filename to load up as it seems to not save the project data once I've set the project state when the script is shut down. So my assumption is that the project saves before any running scripts have had the chance to terminate.

So I think the only solution is to request that the project saves on shutdown - but after all scripts have completed termination (and have been able to set any data in the project state).

EDIT: Your suggestion might work now I've thought harder about it - if I first do a check in the at-exit function to see if the project is dirty or not - it can try to resave the project if it is not dirty (assuming the project has been saved first - then it shouldn't be dirty). This might work and might not produce any unwanted side-effects - I'll try it out.
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal

Last edited by lb0; 01-11-2019 at 04:33 PM.
lb0 is offline   Reply With Quote