I think it a bug. I’m trying to make an inventory and I would like to use a layer to simply show/hide inventory on key press. The problem is that, seems like the layer visibility check condition runs only one time at start and never again even not if I check visibility on key press. If I hide layer by default and run preview, I can show the layer on key press but only one time, I can’t hide the layer any more. If I show the layer by default and run preview, I can hide the layer on key press, but I can’t show it any more and the reason I think it a bug is because I also update a text object every single frame in case the layer is visible or not visible to check if it actually works, and it doesn’t work. It works at start, update the text object but after if I hide or show the layer the text object doesn’t change but it should.
Here is an example project of what I’m trying to do: Project.gdg (18.8 KB)
First, the condition that check if the layer is visible always return the state of the layer at the start of the scene, so it’s effectively a bug that I just fixed.
The second problem is also that you have an event that show the layer, then in the event that is following you immediately hide it because the condition is fulfilled. As there is no “else” in events, you have to use a variable to make sure that events aren’t both executed.
Also, instead of using a variable for the key press, just add a single “Trigger Once” condition. No need for another event nor a variable to do it
Here is the “fixed” project: it won’t work for now until the next version of GD. For now, you’ll have to manually remember the state of the layer in a second variable. Project.gdg (17.9 KB)
You can also ditch the layer visibility, and just create your inventory out of the camera field of view.
Like “set object myInventoryTable at coordinates inventoryCoordsx + 10 and inventoryCoordsy + 5”, where inventoryCoordsx:inventoryCoordsy are either 0 or the size of the screen.
When you press a key, just modify the variables so the inventory objects group will move at the good coordinates (within range or out of the screen).
This way, your inventory will always be visible, but outside of the camera most of the time.
If I use only trigger once condition the events immediatelly execute one after the other as the conditions fulfilled and trigger once condition let the events to run at least one time, so I used “i_pressed” variable basically for same reason why you do “done” variable
If key is not pressed I set “i_pressed = 0” if key pressed and the event is executed I set “i_pressed =1” , this way only one of the events can execute at the time and only once as “i_pressed” need to be 0 and key also need to be pressed to fulfill the condition. So once the key is pressed, in theory, only one of the events can execute and only one time, the key need to be released and pressed again to execute an event.
Though maybe in the very short time frame between change the layer visibility and set “i_pressed” to 1, the other event also get executed quickly as it condition is fulfilled for a very short moment until “i_pressed” is set to 1 but I’m not sure if it the case actually as I never noticed such problem other places, this method always does the job for me also here as at the beginning it hide the layer if it visible and show the layer if it hidden, things go wrong only after as
I always used this method before trigger once get implemented in to GD but also since as trigger once doesn’t solve all problems in such case, though I could use it to set i_pressed to 0 only one time while/when key is released not every frame as long the key is released
But your “fix” in the project and solution to use a variable to store/check state of the layer is more practical, maybe I’ll use it thanks for that
This is an interesting solution, to interact or stop interaction with the inventory I don’t have to check if it visible or not, I can just move it and keep it outside the screen but instead simply change it position, I could actually make it slide in and out and play some nice animations when it moving in and out. I like it