Refactored player events into pVar, now attack animation won’t trigger

I’m refactoring my GDevelop events from separate player logic (p1, p2, p3, p4) into a single dynamic system using pVar.
Previously, the events worked when written separately for each player.
For example (Player 1 event), this one event checked Player 2 against Player 1:
check if p2 is on the same grid as p1
check if p2.team is different from p1.team
check if p1 animation is not already “attack”
if true, p1 plays the attack animation (thus attacking against p2).
I had similar events for p3 vs p1, p4 vs p1, etc., and everything worked.
To reduce repeated work, I changed it into a single dynamic event using pVar so it can handle all players.
However, after this refactor, it no longer works.

I also changed several related events and some global variables, so I’m not sure where the issue started.
Right now I can only trace the logic step by step.
My main goal first is:
how can I make the attack animation trigger again in the dynamic pVar version?

Before

Now

When you’re referring to the inGame child like in this:

You’re using something like
inGame.player[ToString(pVar)].team

That would point to a structure with a child named player that’s a structure like

Which would be the same as
inGame.player.1.team

Unless you changed the structure, I think you want:

inGame[“player” +ToString(pVar)].team

That would give you a child named player1, player2, etc

Which would be like:
inGame.player1.team

Did you make the change to your structure because your for each child uses for every child in inGame.player

Apologies if you changed the format of your structure.

1 Like

Previously it was inGame then player1, player2…
But i decided to change it to:
inGame.player.1
inGame.player.2

1 Like

I think the problem is not the structure. When the refactored events finished for the first time, it kinda work, its just that it failed to play the attack animation.

OK. Then that’s not an issue although using a child that starts with a number even if the number is in text form is frowned against. It can be confusing and possibly create an array instead of a structure. Just verify the array in the debugger. But it shouldn’t be an issue.

Your repeat for each player, does it need all of the players or just the ones currently picked with the conditions in the first event. IDK if you need a pick all players before it.

I’m also not sure about your trigger once conditions. They don’t work well within loops and with instance since they work on an object level. Make sure they’re not causing issues.

It’s usually only necessary to control when the loop itself is triggered and not the events inside it. But it depends on your motives.