ignore my code, and follow Pixie's post, as my code was just to show you the needed logic~mindset~mentality, which is something that you *DO* need to learn (both coding and GUI~Editor requires this logic brain training, unfortunately), and it takes quite a while to train your brain to think in this code-logic, it took me along time to get my brain trained in this code logic.
try to imagine it being you opening and closing a door~window~curtains, and think of all of the possible scenarios (4 in this example):
1. you try to open a closed door: real world behavior (easy logic)
2. you try to open an open door: not real world behavior (hard logic, lol)
3. you try to close a closed door: not real world behavior (hard logic, lol)
4. you try to close an open door: real world behavior (easy logic)
computers are stupid, that's why you got to deal with: 'opening an open door' and 'closing a closed door', something that a human wouldn't try to do.
even what seems like something really simple, can actually be something quite complex to do with computers~programming~coding~GUI~Editor~game making
for a great example of this:
Human:
HK is a male human warrior.
~VS~
Computer:
player.alias = "HK"
player.gender_string = "male"
player.race = "human"
player.class = "warrior"
msg (player.alias + " is a " + player.gender_string + " " + player.race + " " + player.class + ".")
// outputs: HK is a male human warrior.
yeesh! So much work for something we can do so easily, hehe