Prevent Runtime error: No such modifier in node 1

I've created a dialog box script which can create an object and then add and remove modifiers. To remove modifiers one-by-one from the stack (like an undo command), I have added a button:

on but_undo pressed do
(
deletemodifier obj 1
)

Only problem is that it's still possible to try and remove a modifier even when the stack is empty, which results in a runtime error: No such modifier in node 1

Is there a way that I can disable the button if the modifier stack is empty? Failing that, is there a way to prevent it from attempting to delete a modifier if there isn't one there to delete? Or am I just going about this the wrong way to start with?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

Or count the mdifiers:

on but_undo pressed do
(
	if obj.modifiers.count != 0 do
		deletemodifier obj 1
)
pixamoon's picture

`

the simplest way is to just add try(  )catch():

on but_undo pressed do
(
try(deletemodifier obj 1)catch()
)

you can also use callbacks to turn off button, but its bit more complicated

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.