Guys, well explain to me how logic works, I can’t understand anything.
I probably have a contradiction, but I can’t understand why what I did doesn’t work.
I have doors on a level. I want the player, when they get to a door and press the “e” button, to be able to first open the door and immediately close it again by pressing the “e” button.
Why doesn’t this work the way I did?
I have two animations in the sprite of the door “open” and “closed”.
The code works from top to bottom, if the animation is closed - it makes it open. That works fine.
The problem arises when you have another condition underneath it checking if it’s open. Your code checks if the door is closed, makes it open but it also sees that it is open and makes it closed.
What I usually do in these situations is make a boolean variable and when the E key is pressed, set it to true before the sub-events happen.
After the animation changed to open, change the boolean to false.
When you check if the door is open, add a condition to check if the boolean is true. This way it won’t just close immediately after opening.
Still doesn’t work closing. I think the conflict is exactly the same as it was before and everything should be done in one query. It’s just that I have never done it before, so I can’t figure out how to do it all in one query.
You’re running into the same issue. The actions of the first event are such that all the conditions will be met in the second event, so that then gets actioned too, and the animation never appears to change.
Try this instead. It uses a trigger once on the key press player-door collision and a boolean variable to track whether the door animation has been changed in this set of events: