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”.
Why doesn’t it work???
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.
Thank you, but you could show me what it’s supposed to look like.
I really want to learn how to do this. I can’t get started with variables, although I realize that it is necessary.
Please show me how to do it on an example.
Change to key released and add trigger once to the sub events might work if you dont want to use boolean variable
until it still doesn’t work
I need a variable anyway, because I want to check for the key afterwards.
Please explain how to do this correctly
Have a boolean for the door called open
If open is false the animation is closed
If open is true the animation is open
If open is false and e is pressed set the boolean to true
If open is true and e is pressed set the boolean to false
Also you could have a global boolean for haskey…
if false you cannot interact with the door
If true you can interact with the door
I did what you said, but now the doors only open but don’t close.
Put the Trigger once on each condition
still doesn’t work. It opens, but it doesn’t close
Your second event is setting to true you need to change to false
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.
It should be like this, and the “door” variable is set to “false” by default.
You have to seperatw the events so
Boolean false is closed animation
Boolean true is open animation
Collision and e press sets boolean
This needs to be set in the variables of the “door” sprite.
I just can’t figure out where exactly it needs to be set.
I don’t understand, I think I added a logical variable “door” why the closing doesn’t work I don’t understand.
Have I done everything right?
If not, please tell me where the mistake is.
But so far it doesn’t work.
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:
I have all the doors closed by default.
I did everything as you wrote, but the doors still won’t open or close.
Haha, my bad . That animation change action in the last event should be to “open”.
Teach me to rush a copy & paste.
Hallelujah, thank you, it really works. How to add a key check ? I understand also through a variable ?