#effective way to let puzzle elements identify and interact with eachother?

13 messages · Page 1 of 1 (latest)

thin portal
#

i am making a puzzle platformer where i need to match switches and doors (etc) to interact with each other, but not necessarily on a 1-to-1 basis (some switches may affect multiple other devices for example)
with what little i know of the engine all i can think to do is give each set an id as a group and let them identify each other that way, but i feel like there could be a more effective and efficient way to do this.

tight flicker
# thin portal i am making a puzzle platformer where i need to match switches and doors (etc) t...

Depends how tightly coupled you're okay with the door and switches being. You could export direct references between the door and multiple switches. When a switch is flicked, it tells the door. The door then checks if all its switches in the proper position and if they are, unlock/open. A fine solution for hand tailored puzzle games.
You could decouple them using signals if you wanted switches to interact with things other than doors.

thin portal
#

You could export direct references between the door and multiple switches
how would i go about doing this?

tight flicker
#

@export var switch_list: Array[Switch]

#

And then set the references in the editor

thin portal
#

so for the Array**[Switch]** part, how do i get the switches i want to reference in the list for the door?

#

specifically how do i make instanced switches the thing that goes in the list

tight flicker
#

Are you familiar with how exports work? Once you create a switch in your scene, click on the door node. In the inspector you'll see the switch_list array you made. Add an element to that array, and then select the switch from the list that pops up

thin portal
#

i don't know if i was literally supposed to put "switch" as the identifier bc i get this

#

the scene is called "switch" btw

tight flicker
#

Ah, you'll need to create an actual Switch class first. Look up a video on class_name

thin portal
#

works!

#

thank you very much!