Godot Version
4.3
Question
This was working, but now I’ve somehow killed it.
I have two global autoloads:
The script for interactable.gd is…
extends CollisionObject2D
class_name Interactable
signal interacted(body)
@export var enabled := true
@export var prompt_message := "Interact"
@export var prompt_action := "interact"
@export var key_match := false
# every interactable item has its own unique ID
var ID : int
func get_prompt(needed_key):
if not enabled:
return ""
if setup.get_key() == needed_key:
var key_name := ""
# search input key mapping for the key that matches "Prompt Action" on each object
# so you could have more than one action key - one for each object
for action in InputMap.action_get_events(prompt_action):
# if the current key being pressed matches a action key
if action is InputEventKey:
# get the letter (eq "E") so it can be displayed as hint - line 28
key_name = action.as_text_physical_keycode()
prompt_message = prompt_message + "\n[" + key_name + "]"
else:
if setup.get_key() == 0:
prompt_message = "Key required"
else:
prompt_message = "Wrong key"
return prompt_message
func interact(body):
interacted.emit(body)
The script for setup_chests.gd is…
extends Node
var playerstate := {
"key": 0,
"health": 100,
"weapon": "pistol"
}
func get_key():
return playerstate.key
func set_key(newkey):
playerstate.key = newkey
I have a couple of scenes which inherit the interactable class, for example…
extends Interactable
@export var opened := false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
ID = 56
func open_door():
opened = true
enabled = false
visible = false
func _on_interacted(_body):
if not opened:
if setup.get_key() == ID:
key_match = true
setup.playerstate.set_key = 0
print("Opening door")
open_door()
else:
print("wrong key")
prompt_message = "Wrong key"
notify_property_list_changed()
I had a player scene, but I deleted it because I wanted to try something else and that’s when the code broke.
As a noob, I’ve hurt my brain trying trying to understand what happened. The player scene had no references to either of these globals, so I don’t know why it effected it.
How do I fix it…and what exactly has gone wrong?
Thanks in advance.