Getting variables from objects in object group

Hello community,

after a timeless surfing through Gdevelop forum i finally decided to ask a question.

Lets say I have different objects on my scene.
All these objects can be interactable so they are all in one object group “Interactables”.

Each object in this group has its own variable “objectType”. For example objectType=“door”, objectType=“TV”, objectType=“lightSwitch”.

The idea is: when Player is in collision with object from group “Interactables” (we don’t know what is the object) - determine what is the objectType variable value of this object of collision to do action that is tied to the value (if “door” - open door etc)

How can i set up this in my scene?

From the code point its like something to get:
String Interactables.Object(objectType)

Condition
Player is in collision with interactables
Variable objectType = door
E key is pressed

Action
Play sound open door

Condition
Player is in collision with interactables
Variable objectType = TV
E key is pressed

Action
Play sound commercial

Where Player is in collision with interactables
And E key is pressed should be parent folder
Other conditions and actions should be sub events

Thank you for your replay,
but i do not really understand how can I get variable objectType = TV in conditions for current object that is in collision with player?

This variable “objectType” is related to objects. I cannot just type in conditions “Variable objectType = door” or maybe I don’t know some details…

I use lots of copies of the same object in my game scenes. In order for the game to know what instance of the object I want to target, I use an object variable, like you have described. In my case the variable is called id. So id = door, id = book, id = computer etc. In my conditions I tell GDevelop what instance I want things done with, like this:

image

E.g. if the object’s id = door and the player’s distance to it is below 100 pixels > change scene.

This stops the event’s actions affecting all instances of my green circle object; they will only affect the one with the id of door.

(ignore the numbers and arrows on my object - that’s to help me with layout and is not related to your question)

Thank you guys for the explanation!
I think for now my question is resolved

1 Like