Is it really that hard? Is my google-fu obtuse? How the heck do I make a cancel button that CANCELS the execution of the rest of the script?
My script is dumb. I'm not a good coder, I know that, but here's what I've got:
I'm automating INDD CScloud. Script first opens a Window, operator has options as radio buttons. at bottom are standard "OK" and "Cancel" buttons, then the script has some functions that do stuff based on the options shown in the Window. What I want to happen is ALL CODE EXECUTION to STOP when I hit the "Canel" button. Thats it! nothing fancy! but all it seems to do is close the dialog Window and continue without registering changes. GRRR.
here's my crappy code:
var asker = new Window ("dialog","Answer Some Stuff!");
var firstselector = asker.add ("panel", undefined, "Which Thing First?")
firstselector.alignChildren = "left"
firstselector.preferredSize = [250,100]
thing1a = typeselector.add ("radiobutton", undefined, "Thing 1a")
thing2a = typeselector.add ("radiobutton", undefined, "Thing 2a")
thing3a = typeselector.add ("radiobutton", undefined, "Thing 3a")
thing1a.value = true;
var secondselector = asker.add ("panel", undefined, "Which Thing Second?")
secondselector.alignChildren = "left"
secondselector.preferredSize = [250,100]
thing1b = secondselector.add ("radiobutton", undefined, "Thing 1b")
thing2b = secondselector.add ("radiobutton", undefined, "Thing 2b")
thing3b = secondselector.add ("radiobutton", undefined, "Thing 3b")
thing1b.value = true;
var thirdselector = asker.add ("panel", undefined, "Do Thing Three?")
thirdselector.alignChildren = "left"
thirdelector.preferredSize = [250,75]
certyes = thirdselector.add ("radiobutton", undefined, "Yes")
thidno = thirdselector.add ("radiobutton", undefined, "No")
thirdyes.value = true;
asker.add ("button", undefined, "Do It!", {name: "ok"});
asker.add ("button", undefined, "Cancel", {name: "cancel"});
asker.show();
var mainPart = function(){
if (thing1a.value == true && thing1b.value == true)
{
do some stuff
}
if (thing2a.value == true && thing1b.value == true)
{
do some different stuff
}
})();
var secondPart = function(){
if (thing3.value == true && thing1b.value == true)
{
do this other stuff
}
if (thing3.value == true && thing2b.value == true)
{
do some other stuff entirely
}
alert("All The Stuff Is Done!");
}
)();
All I want to happen is that when the operator clicks the "Cancel" button the script exits and mainPart
and secondPart
are NOT executed.
I tried using a .onClick
, like this:
var cancelBtn = asker.add('button',undefined,'Cancel');
cancelBtn.preferredSize.width = 175;
cancelBtn.onClick=function(){
exit();
}
but apparently exit()
is not valid and the code just keeps going... so i tried break
, it errors about "illegal use of break outside a loop" but then proceeded to execute the rest of the code anyway...
help me be less dumb, please.