Well, if you were using two separate commands to open and close your door the script would be simpler. Using a flag as a toggle permits you to use a single command that has the net effect of two. The side effect is that it complicates your script somewhat.