0 votes

I want to load an instance of my inventory scene with the press of "i" and then close it again with the press of "i". At the minute my inventory scene is loading and is visible but when I press i again i think it closes and then opens again instantly.

Here is the script:

Player script:

func unhandledkeyinput(event):
if Input.is
actionjustpressed("openinventory"):
var inventory = load("res://Scenes//Inventory.tscn").instance()
add
child(inventory)
print("i")
get_tree().paused = true

Inventory script:

func unhandledkeyinput(event):
if Input.is
actionjustpressed("openinventory"):
queue
free()
get_tree().paused = false

when I press "i" when the inventory is up it prints "i"

Cheers for the help.

in Engine by (12 points)

1 Answer

0 votes

Maybe you need a cool-down timer.

So when after open (or close) the inventory screen:

1) create a global flag, for example is_active = false which will cause your script(s) to ignore input, for example

if Input.isactionjustpressed("openinventory") && is_active:

2) start a short timer. On timer complete, set the flag is_active = true so input will be accepted again

by (541 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.