| 17 | |
| 18 | == Interrupt/abort Support == |
| 19 | |
| 20 | If your script does any iteration, it should support being interrupted by the user, in case it takes too long or enters an infinite loop. !WorldPainter cannot kill your script in such a case, so you need to support interruption explicitly, by using one of the following two methods: |
| 21 | |
| 22 | * `wp.interrupted` - this is a boolean property which you can check, and if `true`, cleanly abort your operation, cleaning up in so far as necessary. |
| 23 | * `wp.checkForInterrupt()` - this is a function you can call which does nothing as long as an interrupt has not been requested, and throws an exception if an interrupt ''has'' been requested. Use this if it is OK to just abort whatever the script is doing without doing clean-up. |
| 24 | |
| 25 | Do either of these in some inner loop, where it is guaranteed to be reached even if your code enters an infinite loop at a higher level. |
| 26 | |
| 27 | Note that any changes the script might have already made to the Dimension are not automatically rolled back. The user will have to do that by closing the script window and activating the Undo action using the toolbar button or by pressing Ctrl+Z. |