Identifying a randomly selected object to use in condition

Hello everyone,

Whether you use an action to ‘Pick a Random Object’ or use an array to pick a random child (I’m new to this, sounds sketchy AF when I see this, still, lol), what expression do you write in the conditions under that so the actions will only impact this selected object?

Say I have 10 NPCs, put their objects in a group, write an action to pick a lucky one at random, then is there a ‘Picked_Array.Child(NPC)’ I could put in condition to only apply actions to this character? Then perhaps, at the end of all this group event, delete that selection so the list is back to being available?

The way i’ve been doing things so far (I started using GD like a week ago so I’m really unsure about most things here) is to trigger once a Pick random object, give it a boolean value and stay in sub-events so it’s kinda different from the rest of the group, not sure it’s the best way to go about it. Here’s what I came up with:

I’m a solid 90% sure there is a much more efficient and clever way to do this but I must confess that when it finally worked, I was overjoyed. First problem solved, thanks GD!

Hope it’s clear, at least.
Thank you for your help!
Maxime

I’m not sure what your code is doing, but upon picking an object, your code in any subevents and any below events (unless specified otherwise) will only act on that object, unless its target is another object type. Ask for more clarification if needed. :slight_smile:

2 Likes

You seem to have an understanding of the concept. Conditions work like filters. Without any conditions the pick a random object would pick from all of the instances or objects. You can reduce the choices by using any of the conditions like object variables or animations or location or any number of conditions. Each condition would further filter the pick list.

Sub events inherent the current pick list until you either use pick all objects, start a new event or a lower sub event meaning close to the left side. Each indentation or sub event maintains its own pick list.

1 Like

Thank you both for your feedback.

So, in essence, there is no need to ‘specify’ further the selected, filtered down element, because a subevent will be sufficient. I’ll try to simplify this code further, to learn more.

@Oddlaceguy49, this is the ugly sprites I made just to test the code :
https://games.gdevelop-app.com/game-355d476f-46bd-494a-a7b3-11c7d96f8eb2/index.html

3 different objects ‘NPCs’. I put 2 instances of each to see if they would act independently from each other too, which they do (which is awesome).

Thank you again for your help.

1 Like

Those cube characters are awesome. I’m all for using doodles. I mostly play around with concepts in GD. So, I don’t worry about the graphics.

1 Like