Devices that activate generic actions on a target

I’ve been trying to search for this but it’s been difficult to find anything about it.

I’d like to make devices such as buttons, levers, traps, etc. that trigger other generic devices, which may have very different effects from each other and do different things.

I made a rough implementation with groups and ids, I can reliably add interactable objects to a group and trigger a single action on objects in another group, by finding the right ones through an ID and then applying an action, like in the screenshot.
I made a slightly different variation of this to only activate when a specific keycard is in the inventory but the problem remains: in the end the event chain can only do one kind of action at a time and I would have to repeat a lot of events if I want the action to be different, like deleting an object, or moving some object, or anything else really.

I’ve been wondering if I can do better, I’ve been getting into custom extensions and I’ve been trying to make something that can work like this but the limitations in what objects can be picked is making this pretty hard, I can’t call behavior functions on a group object, I can’t tell something to just “do your thing” like I could in classical programming languages.

What’s the gdevelop approach to do something like this?

GDevelop is pretty flexible and has some more powerful features like extensions, behaviors and custom objects (prefab). The only problem is with a smaller group of users, there aren’t as many resources.

You can move events into extensions that you call just like builtin conditions, actions and expression.

You can create behavior which contain the various functions and the assign it to an object. This can add automatic events and actions and conditions that can be called.

One of the newer features are custom objects or preefabs. They make complete custom objects like sliders, toggle switches or joysticks. They contain everything. It’s a collection of other objects and images with all of the other functions. You just add it to the scene and it works. You treat it like any other builtin object

These are more advanced but any of them can help to make projects less repetitive. You should only need to write something once and then call it using different objects or parameters.

As far as strategy. IDs are fine for things. You can also use things like one object picks the nearest instance of another object. Or through collision with each other. Or use a 3rd object as a container. If “a” is a 3rd object like a wire or just a container. If a is collision with b and a is in collision with c then do something. The 3rd object wouldn’t even need to be visible.

For example, you could create a custom object or a behavior that represents a card reader. Once the object(s) is added to the project, you could add it anywhere. It could have conditions to handle collisions with access cards and actions to open doors.

You can have a 2nd object or behavior for the key cards. You can assign IDs, names or colors.

The final object or behavior could be a door. The door would have actions to open/close and conditions like isOpen or is Locked.

The card would interact with the card reader through collision. The card reader to the door through an ID, or proximity or collision with each other or a third object.

I went on a bit but I wanted to be thorough. Remember sometimes complex is just complex. Simple is good. More isn’t always better. And some other words of wisdom that I found in a fortune cookie.

Thank you, that gave me some ideas and I experimented with custom objects and I actually got something workable!
Here’s what I did:
I made two custom objects with a sprite (and eventually more) each, one for the button and one for the object that is acted on by the button, then I added an “Activate” function on both.
The activate function on the acted-on object has Id as a parameter, and checks the Id as condition.
The activate function on the button has the other custom object as parameter.
Important caveat I found and wasn’t really mentioned: custom objects need to create themselves in the onCreated event or nothing will happen, it’s also a good place to set some other initial variables like timers for cooldown and such.
And that’s enough, now I can just create these custom objects and instantiate them, set the Id in the variables and they’ll work, if I add all the buttons to a Buttons group and all the activable objects to their own group I can just call Activate as needed on the buttons group and on the destination group as target.

The cool part is that now I can use Properties to give each object type different behaviors, like switches that toggle, switches that only enable, switches that only disable, etc, the same for doors that open and do other stuff, this really solved my problems!

1 Like

I’m happy for you. I’m also relieved that you have the knowledge/experience to use them. I’m usually hesitant to recommend things more advanced because I don’t want to overwhelm new users. I wish building extensions were more user friendly. The setup is a bit cluttered. I wish it was more organized with fewer seperate parts.

I agree. I wish you added objects to a prefab like in a scene. Maybe eventually that will happen. It’s fairly new. Your concept definetly makes things more efficient, less repetitive and more drag and drop.

Edit: The nice part is once you have one built, you can use it as a template making the others much easier to create.

My only gripe is that it takes a lot of brainpower to design these custom objects compared to classical programming, I suppose it’s because there are a lot of moving parts in different tabs and windows and it’s hard to keep them in mind all at once, it takes some getting used to but it does seem like a pretty powerful system

1 Like