For each object not working right [fixed, for real this time]

Since dragging each NPC graphic to each NPC and saying, “at beginning of scene, if graphic is in collision with actual NPC, go stand in the center of the NPC object,” would be a lot of work, I want to just drag NPCs where I want them, and then at the beginning of the scene, they already have their graphic (the actual person-image) standing in the middle. So I did this:


But instead of a graphic being placed on each NPC, either one of the NPCs didn’t get a graphic, or else, its graphic was placed on the other NPC.

Please, does anybody know what went wrong, and how to fix it?

Hi,
your for each events work, the problem are the condition-less events below, because all the playerHolo and NPCHolo objects are changed to the position of one of the player or NPC objects.

There are two solutions:
The easy one: just use the sticker behavior and stick the …Holo-objects to the player/NPC object. Both objects will move together and you don’t need any extra events for that.

The more tricky one: use the ‘link two objects’ action and condition. Here the sequence of linking the objects is important. Linked Objects - GDevelop documentation The wiki shows an example and you can also find some forum topics which explain that.

Just for clarity. The linking order doesn’t matter, it’s the object order when picking the linked objects.

If you link object A with object B then you can either pick the object As that are linked to object B or the B objects linked to object A.

1 Like

Yeah, the “Basic Artificial Intelligence” example provided appears to have exactly what I want (almost). I’ll try it.

Yeah, thanks. I didn’t know what the linking objects thing did before. It works exactly as imagined.

Oh, wait. No. Now, the objects aren’t stuck on the NPCs. It worked perfectly well for the player, which uses the exact same formula, but for the NPCs, the holos (holograms, since it’s just an image of representation, rather than the actual thing) don’t follow their linked NPC’s position.

I’m guessing you’re not sticking NPCHolo to the NPC object in the “Repeat for each instance of NPC” event, immediately after the NPCHolo is created?

Actually, I am.

It says, at the beginning of the scene, for each object of NPC, create NPCHolo at the centerpoint of NPC, and then link the two objects, immediately after.

Oh, and my player only worked because I had set the playerHolo’s position to the player’s position elsewhere, but that only works for singular objects, like the player.

This may work, if nothing else, but the potential bugs with this are obvious:

GDevelop 5 - Deeply Yarn (Stick objects)

Linking isn’t sticking.

Are you moving each NPCHolo by using a repeat for each NPC with the additional condition to get the linked NPCHolo object? Something like this:


However, I’d suggest you use the Sticker behaviour on NPCHolo - it’s a lot simpler and does the moving for you:

1 Like

I was using the top one, minus whatever that loose, bottom event was, but I just converted it to sticker. That works for now, but I wonder if it might stick to the wrong NPC in a crowded area, or stick NPCs together by mistake.

It won’t. You are iterating over each NPC object and creating a new NPCHolo that is then stickered to it. That sticker action only applies to the current NPC object and the newly created NPCHolo. All other NPC and NPCHolo objects are not in scope at that point.