Team selection system


Hi everyone! I’m developing a soccer game in GDevelop. I’m having trouble creating the logic (event programming) for the player to select their team and the opponent’s team. I’d be grateful if anyone could help with any information.

Team select is easier if you treat it as data flow, not one big event sheet. Split it into three: pick, store, spawn.

1. The pick (team select scene)

Put a button object per team (or one TeamButton object with one instance per team). Give each instance an instance variable teamId (string), e.g. red, blue.

On click on TeamButton:

GlobalVariableString(playerTeam) = TeamButton.VariableString(teamId)

Use Trigger once on that event so it fires on the click, not every frame. To show which one is currently selected, highlight where TeamButton.VariableString(teamId) = GlobalVariableString(playerTeam).

2. The opponent

Let the player pick both, or pick one and roll the other. For the roll, keep the list of teams in a global structure or a global string array and pick one that is not the player’s:

GlobalVariableString(opponentTeam) = GlobalVariableString(teamList[Random(GlobalVariableChildCount(teamList))])

repeat while GlobalVariableString(opponentTeam) = GlobalVariableString(playerTeam)

A while with Trigger once is fine here; it exits almost immediately.

3. Team data as a global structure

Don’t duplicate events per team. Store the rosters once:

Teams.red.name = "Reds"
Teams.red.rating = "82"
Teams.blue.name = "Blues"
...

Then in the match scene read them through the selected id:

GlobalVariableString(Teams[GlobalVariableString(playerTeam)].name)

Adding a team later becomes data entry, no new events.

4. Getting the choice into the match

Scene variables reset when you change scene, so the selection must live in global variables. In the match scene, in “At the beginning of the scene”, read playerTeam / opponentTeam and set up spawns, colors, rosters from that.

5. Two traps that usually cause the mess

  • Storing the pick in a scene variable, then wondering why the match scene sees nothing.
  • Comparing ObjectName() while several button instances are picked, so you save the wrong team. Pick via the click event (or a picked instance variable) and store from that instance.

If you post the events you have now for the select screen, I can point at the exact block that is fighting you.