Interactables Script

The Interactables script (Scripts/Interactables.gd) should be used to store any Interactables that need to be accessed across Rooms, i.e. Interactables that can be added to the player's inventory (see Data) or Interactables that move between different Rooms. For Room-specific Interactables, use that Room's room_interactables property.

The Interactables script extends InteractableInterface, so for more detailed information at associated methods, look there.

Interactables within a given InteractableInterface (like the Interactables script) should all be given unique identifiers. The identifier should be identical to the name of the object you want the player to use to interact with it, i.e. if you want the player to be able to type "open box" then the identifier for that Interactable should be "box".

Interactables in this script will override Interactables with the same identifier in a Room's room_interactables property, so consider anything defined here to be a unique object that should not be replicated elsewhere.

Tutorial

Let's look at how to add Interactables. Let's make a new Interactable called 'box' in our Interactables script:

var box_interactable = Interactable.new("box");

It doesn't have any interactions, so it's pretty useless right now. Let's add one called 'open':

box_interactable.add_interaction("open", func () -> String: return "There's nothing inside! What a rip-off.")

Now, we can register our box to the Interactables script by calling add_interactables in the script's _ready() function:

func _ready() -> void:
    add_interactables([
        box_interactable,
    ]);

And that's it! Now we can access that interactable by name from anywhere in the project with get_interactable or attempt an interaction with it with attempt_interaction:

var gotten_box = Interactables.get_interactable("box");

print(Interactables.attempt_interaction("box", "open"));