(Solved) Cant use Boolean Variable when Spawning objects?

I have a chest and I want it to display an “E-button” sprite above the chest when a player is within so far of the chest to tell the player what key to press to open the chest. I have it where it will display the sprite and delete it after I open the chest. But when walk away and come back it shows up again. I tried using a Boolean variable to control when the chest has already been opened. But with the variable set it won’t load at all or let me open the chest. I’m just Tryna make it where the E-Button won’t be displayed after I have already opened the chest.

This is in game with Boolean Variable set

The code with Boolean Variable set

The E-Buttons Variables

In game before chest is open without Boolean Variable

In game after chest is open without Boolean Variable

In game after chest is open without Boolean Variable and I have walked away and come back(the E-Button reappears)

Code without Boolean Variable being used

Hello, HoepherGames

I don’t think you need to make use of the Boolean variable. Try adding a condition to the event that compares the distance of the Knight3 to the Chest that verifies that the animation of the chest is the one that is closed.

1 Like

Hi, your code with boolean is a bit off. At the beginning of the scene you set the deleteEButton-variable to true and later in your events you delete the button when the deleteEButton-variable is true. There is no event that sets the variable ever to false. You can fix that by setting the deleteEButton-variable at the beginning of the scene to false (which makes also more sense anyway).

1 Like

All conditions within an event need to be true so & and isn’t needed except for when with an OR for things like if a=7 or b=7 and c=1

I think the issue is that it’s checking the value of the ebutton before the object is created. It won’t trigger unless there’s already an ebutton in the scene. If you want it as a one-time popup then you can use a scene or global variable. If you want it for each chest then you could use a chest object variable instead.

This is an example of and and or This would trigger something if the scene just started or when the cursor is on NewSprite and if the button was just released.

1 Like

thank you, this is the code that worked for me.

1 Like