PDA

View Full Version : Pause script for user input


JHaywood
03-09-2012, 09:07 PM
I have some cases where I need to pause the execution of a script, ask the user to make a decision about something, and then resume based on their answer. Usually, a simple querybox is fine, but sometimes I want more than just a yes or no answer. In those cases, I need to make my own rollout with the appropriate buttons, but I've never been able to find an elegant way to just stop the script and wait for one of the buttons to get pressed. The way I've been doing it is to create one function that starts the process and creates the rollout. And then have a "continue" function that is called from within the rollout itself, so that clicking one of the buttons calls the continue function and passes in some value that tells me which one they've pressed.

Is there a simpler way that doesn't involve multiple functions and can just be called within the main function so that the script will pause and wait? Will using a .Net MessagBox stop MaxScript execution? What about using a modal dialog? I haven't tried either of those, but they just came to me as I was writing this. :)

spacefrog
03-09-2012, 09:23 PM
not sure if modal really stops script execution, it still reacts to use input
But It even stops some parts of Max's main message loop
eg. progressive viewport updates are not occuring when a modal dialog is opened via maxscript ...

EDIT:

just tested and yes, modal blocks further script execution, but still allows you to react on UI input on the current (modal dialog). As you can see the code is blocking exactly on the creatdialog line, even DestroyDialog() cause exeuction to be continued after that line...

-- modal test
rollout modalRollout "Test"
(
label test "TestLabel"
button btTest "Close Me"

on btTest pressed do
DestroyDialog modalRollout
)

createdialog modalRollout modal:true

for i=1 to 10 do
(
print i
sleep 0.5
)

denisT
03-09-2012, 11:05 PM
as spacefrog said the solution is very simple. just popup a modal dialog.

denisT
03-09-2012, 11:28 PM
something like this:

try(destroydialog mainRol) catch()
rollout mainRol ""
(
checkbutton cacl_bt "2 X 2" width:60 across:3
label lb "=" offset:[8,3]
edittext tx text:"???" width:54 readonly:on offset:[0,2]

fn ask result:"" =
(
rollout askRol "Do you know?"
(
local result = if result == undefined then "" else result
local action

edittext tx text:result rewidth:40 offset:[0,0]
button yes_bt "Yes" width:60 across:2
button no_bt "No" width:60

on yes_bt pressed do
(
result = tx.text
action = #yes
destroydialog askRol
)
on no_bt pressed do
(
result = "---"
action = #no
destroydialog askRol
)
on askRol close do
(
if action != #yes do result = "---"
)
)
askRol.result = result
createdialog askRol modal:on
askRol.result
)
on cacl_bt changed state do if state do
(
tx.text = ask result:tx.text
cacl_bt.state = off
)
)
createdialog mainRol

CGTalk Moderation
03-09-2012, 11:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.