Notifications
Clear all

[Closed] destroyDialog & local scope

Hi all,

I’ve stumbled upon a splinter in my foot…

function displayRollout _rollout =
   (  
   	try (destroyDialog _rollout)catch()
   	createDialog _rollout 550 80 posX posY style:#(#style_sunkenedge)
   )

destroyDialog doesn’t actually close the rollout when it’s in a function I tried passing the argument by reference, but it doesn’t seem to work either.

Is there any way to make it work?

7 Replies
 eek

is _rollout an existing object (rollout) that your passing to the function? I.e can it be called from the command line? And by creating the rollout inside a function is it in local scope? and so the destroyDialog cant see it?

1 Reply
(@groutcho)
Joined: 11 months ago

Posts: 0

From outside scope, the debugger watch manager displays

**Undeclared variable : _rollout

but with the break() in the function’s scope just before destroyDialog it displays

Rollout:rlt_testrollout

Note that when I click a custom close button on the rollout it actually closes.

on btn_closeRollout pressed do
        destroyDialog rlt_testrollout

But it’s called in the rollout’s scope.
So if the user forgets to close the rollout and launches the script again, the old rollout is still there, and you can’t close it at all, you need to restart max.

function displayRollout _rollout =
   (
  	 try (destroyDialog _rollout)catch()
  	 createDialog _rollout 550 80 posX posY style:#(#style_sunkenedge)
      	 try (destroyDialog _rollout)catch()
   )

The second destroyDialog works… but not the first !

wrong answer

you are trying to destroy not created dialog. at that moment old dialog pointer already overwritten by new one, new pointer is a pointer to rollout but not to dialog.
it should be:


global dialog
rollout rol "" 
(
)
fn makedialog =
(
	try(destroydialog dialog) catch()
	dialog = rol
	createdialog dialog
)

DenisT, it doesn’t seem to be the problem. The problem was that the rollout was registered as a global variable. When i set it to local it worked. Strange.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

nothing is strange. everything in your sample works as expected. could you show how you register the rollout?

You’re right, now it works with your method. The dialog is stuck only when the script is stopped by an error.