[Closed] How to stop/exit a script is something turns false?
Hello,
If I have a script that demands the user to do something special, example a messagebox that says “You need to save your maxfile Before you continue, would you like to save it now?” Yes/No.
If the user says yes, the save dialog comes up, but if the user click no, I want the script to shut down/Close (so the user must re-run it again).
Is that possible in maxscript?
Regards
Try this:
ContinueLater = false
if (queryBox "save?" title:"I'm asking you!" beep:false) == true then
(
--- when yes is clicked
print "clicked yes"
if (getMAXSaveFileName() != undefined then ContinueLater = true -- if the user saved the file and didn't cancel the dialog
)
else
(
print "clicked no" --- clicked no, cothing happens
)
if ContinueLater == true do
(
--put all your stuff here
print "jojojo"
)
edit: changed comments
Thanks, I try this when I come home, but just by looking at the code, it seems it doesn’t work the way I want but I might be wrong.
I need to terminate the script if the user click on NO (ecual to if you Close an application by clicking on the red cross button on the top right of the dialogbox).
The script I am building demands that the current max scene is saved Before using the script (else the script doesn’t work the way it should). That’s why I want to check if the current scene is saved or not. If the user have saved it Before the script runs, all is fine, no question is asked. But if the user runs the script with a unsaved scene, the script ask the user if he want to save it now. If the user say yes, the save dialog comes up and you can save and the script continues to run the way it should. But if the user say no, the script will close and you will need to run it again.
All the code is done, the only thing that’s missing is the part of when the user click no
Something like this may work for what you need:
(
try (destroydialog ::RO_SET_WIRE_COLOR)catch()
rollout RO_SET_WIRE_COLOR "Set Wire Color" width:192 height:64
(
button bt_set "Set Wire Color" pos:[16,16] width:128 height:32
colorPicker cp1 "" pos:[144,16] width:32 height:32
on bt_set pressed do
(
filename = undefined
answer = yesNoCancelBox "The file must be saved before."
case answer of
(
#yes: filename = getMAXSaveFileName()
#no: return (destroydialog ::RO_SET_WIRE_COLOR)
#cancel: return()
)
if filename != undefined do
(
saved = saveMaxFile filename
if saved then
(
with undo on geometry.wirecolor = cp1.color
)else(
messagebox "File could not be saved."
)
)
)
)
createdialog RO_SET_WIRE_COLOR
)
YOu can also read up on the checkForSave() method in the maxscript help.