For what you want to do, typically you don't "undo". You duplicate the starting image (once for each blur level) and apply your changes to the copy then throw away the copy after you have exported it. This is much faster because since the copy is throw-away, you can totally disable undo on it.
And undo-group-{start/end} don't enable the undo, they just lump whatever happens between the two as one undo step in the UI, so typically you bracket all the code of your script with them, and the user can undo your script with one Ctrl-Z, instead of one Ctrl-Z per change done in your code...
Do you really need the image to be indexed or do you just want 5 levels of gray? Because if you use auto-indexing, 1) you get a different color map for each image, which can be a problem down the line and 2) you aren't even sure that you get exactly the same result each time (since there is a bit of randomness involved). if you just want 5 levels of gray you can use gimp-drawable-posterize (see Colors ➤ Posterize in the UI).
Given the questions that you are asking you have not written much code before?
Do you know you can also write the scripts in Python, which is a much simpler language?
And undo-group-{start/end} don't enable the undo, they just lump whatever happens between the two as one undo step in the UI, so typically you bracket all the code of your script with them, and the user can undo your script with one Ctrl-Z, instead of one Ctrl-Z per change done in your code...
Do you really need the image to be indexed or do you just want 5 levels of gray? Because if you use auto-indexing, 1) you get a different color map for each image, which can be a problem down the line and 2) you aren't even sure that you get exactly the same result each time (since there is a bit of randomness involved). if you just want 5 levels of gray you can use gimp-drawable-posterize (see Colors ➤ Posterize in the UI).
Given the questions that you are asking you have not written much code before?
Do you know you can also write the scripts in Python, which is a much simpler language?