Frequently Asked Questions > Practical Questions > Working with Scripted UI >

# How do I uncheck a MacroScript button correctly?

MAXScript FAQ > Scripted UI > How do I uncheck a MacroScript button correctly?

## A user asked:

Let's say you have a macroscript button that opens a dialog. Now you'd like to take advantage of the isChecked handler to show the button being checked when the dialog is open and when pressed again (unchecked) will close the dialog. So far so good. Now the user closes the interface using the [x] button.. or any other means except pressing that same macroscript button. How does one go about un-checking that macroscript button?

## Answer:

Here is one possible way to implement this behavior using a "private global" variable (local to the macro Script's scope) which holds the current open/closed state.

This variable can be set from inside the On Close() handler of the rollout so when you hit[X], it forces the3ds MaxGUI to update and uncheck the button.

This can be done using a global variable (if you want other scripts to be able to force your script / dialog to close).Also, more error checking could be added, but the general idea is this:

EXAMPLE
    macroScript test category:"Tests"
    (
      local isOpen = false --initialize to false (closed)
      rollout myRollout "MyRollout"
      (
        label lbl_hello "hello world"
        on myRollout close do --when closing, set to false and redraw GUI
        (
          isOpen = false
          updateToolbarButtons()
        )
      )
      on execute do
      (
        if isOpen then --if open, close it
        (
          destroyDialog myRollout
          isOpen = false--and lower the flag
        )
        else --if closed, open it
        (
          createDialog myRollout
          isOpen = true --and raise the flag
        )
      )
      on isChecked return isOpen --return the flag
    )

#### See Also

- Frequently Asked Questions