I have a problem that you may be able to clarify for me.
I'm updating an old script with a menu made in ScriptUI who has a button (this is just an example, the final script will have more buttons).
I was advised to put the menu inside a function, using "return" to stop the script when certain conditions were not met (apparently "exit" doesn't work in photoshop).
When the button is pressed it should activate a control function (CheckFunction) that stops everything in case of a problem (I chose to put the control in a function to avoid unnecessary repetitions as there will be a few buttons with the same control).
Not knowing if an external function can be called from inside a function (I just started doing simple scripts, I don't know much), I nested the functions.
The problem now is that the button calls multiple consecutive functions (I don't think it's avoidable), and using return on the first one (the control one), it stops the control function, but not the rest of the functions that are called generating various errors.
Is it possible to stop the other functions or do I have to write the script in some other way?
I give an example of how the menu is done for clarity.
function Menu() {
if (documents.length == 0) {
alert ("Open a file first");
return;
}
// here goes the dialog window with the button I will call button1
button1.onClick = function() {
CheckFunction();
Function2();
Function3();
}
function CheckFunction() {
if (condition is not met) {
alert ("Condition not met");
return;
}
}
// here goes the other functions
DialogWindow.show ();
}
Menu();
Once used return in CheckFunction() does not stop Function2 and Function3 which are called creating errors.
If I need to rearrange the whole script I will gladly do it since scripting is not my strong suite.
Do you have any solutions/advice for me?