Skip to content

SwitchInteraction ​

Inherits: InteractableObjectInteraction < Interaction < Resource

Inherited by: LightInteraction

Switch interaction - handles ON/OFF toggle with lock mechanics and audio feedback Base class for LightInteraction and other toggle-based interactions

Properties ​

SwitchStatecurrent_stateSwitchState.OFF
boolstarts_onfalse
boolcooldown_enabledfalse
floatcooldown_duration2.0
Stringswitch_on_animation"switch_on"
Stringswitch_off_animation"switch_off"
Stringbroken_animation"broken"
Stringlocked_animation"locked"
SFXSelectionswitch_on_sound
SFXSelectionswitch_off_sound
SFXSelectionlocked_sound

Variables ​

Timercooldown_timer

Methods ​

voidsetup_for_interactable_objects( interactable: InteractableObject )
boolcan_interact( player: Player )
voidstart_interaction( player: Player )
voidend_interaction()
Stringget_interaction_prompt()
voidon_locked_reaction()
floatget_cooldown_remaining()
voidset_switch_state( new_state: SwitchState, triggering_entity: Entity = null )
SwitchStateget_switch_state()
boolis_switch_on()
boolis_switch_off()
boolis_switch_broken()
boolis_switch_on_cooldown()
voidbreak_switch()
voidturn_on()
voidturn_off()
voidtoggle()
Dictionarysave_state()
voidload_state( state: Dictionary )
voidcleanup()

Signals ​

switch_turned_on( entity: Entity ) ​

Emitted when the switch is turned on.

switch_turned_off( entity: Entity ) ​

Emitted when the switch is turned off.

switch_state_changed( new_state: SwitchState, entity: Entity ) ​

Emitted when the state of the switch changes: the new state and who changed it.

Enumerations ​

enum SwitchState ​

The states of a switch: on, off, broken or in cooldown.

  • ON = 0
  • OFF = 1
  • BROKEN = 2
  • COOLDOWN = 3

Property descriptions ​

SwitchState current_state = SwitchState.OFF ​

The state of the switch now.

bool starts_on = false ​

True when the switch is on when the game starts.

Cooldown

bool cooldown_enabled = false ​

True when the switch cannot be used again for a while after a use.

float cooldown_duration = 2.0 ​

How many seconds the switch waits after a use (when the cooldown is on).

Animations

String switch_on_animation = "switch_on" ​

The animation of turning the switch on.

String switch_off_animation = "switch_off" ​

The animation of turning the switch off.

String broken_animation = "broken" ​

The animation of a broken switch.

String locked_animation = "locked" ​

The animation of trying a locked switch.

Audio

SFXSelection switch_on_sound ​

The sound of turning the switch on.

SFXSelection switch_off_sound ​

The sound of turning the switch off.

SFXSelection locked_sound ​

The sound of trying a locked switch.

Variable descriptions ​

Timer cooldown_timer ​

The timer of the cooldown.

Method descriptions ​

void setup_for_interactable_objects( interactable: InteractableObject ) ​

Sets the switch up on its object: finds the nodes it needs and applies its starting state.

bool can_interact( player: Player ) ​

Can the player use the switch now (in range, the object is not broken, the requirements are met)?

void start_interaction( player: Player ) ​

The player uses the switch.

void end_interaction() ​

Does nothing: a switch has no end of interaction.

String get_interaction_prompt() ​

The text of the prompt above the object for its state now ("Open", "Climb" ...).

void on_locked_reaction() ​

Called when someone tries the object while it is locked: plays the locked sound and animation.

float get_cooldown_remaining() ​

How many seconds of the cooldown are left.

void set_switch_state( new_state: SwitchState, triggering_entity: Entity = null ) ​

Force the switch to a specific state

SwitchState get_switch_state() ​

Get the current switch state

bool is_switch_on() ​

Check if switch is currently on

bool is_switch_off() ​

Check if switch is currently off

bool is_switch_broken() ​

Check if switch is broken

bool is_switch_on_cooldown() ​

Check if switch is on cooldown

void break_switch() ​

Break the switch (set to BROKEN state)

void turn_on() ​

Turn switch on (force without entity interaction)

void turn_off() ​

Turn switch off (force without entity interaction)

void toggle() ​

Toggle switch state

Dictionary save_state() ​

The state of the switch for a save.

void load_state( state: Dictionary ) ​

Restores the state of the switch from a save.

void cleanup() ​

Gives its timers back and clears what it holds (the object is going away).