Best practice for multiple text objects

If you have two players, and you have a different icon for each player, you can create one sprite object (‘Player’) and add both icons as animations (naming them appropriately (e.g. ‘Player1’, ‘Player2’)).

But if you want to have each player’s score displayed, what’s the best way to do this? I see two options:

  1. Add two separate text objects (named something like ‘ScorePlayer1’ and ‘ScorePlayer2’)
  2. Add one text object and give it a variable ‘Player’ which can be ‘1’ or ‘2’

I like the simplicity of option 2 and how it’s similar to what you’d do for sprites, however I wonder how easy it is to update each player’s score independently… Has anyone had experience with something like this? Any suggestions, best practices?

I would use object linking.

Have only 1 text object.
Each player store it score inside an object variable.
In case each player is a different object not only instance of the same, add each player to group.

At the beginning of the scene, create text object For each player and Link text object to player.
After, go through each text object every frame or every x second and For each text object, take in to account linked player object and get the score from the object variable and update the text with the score.

So the event would look something like this:

[code]Condition:
At the beginning of the scene

Action:
For each Player:
Create Text object at position Player.X(), Player.Y() - 10
Link Text object to Player[/code]

[code]Condition
If Timer > 1 second

Action
For each Text:
Take in to account all Player linked to Text
Do = ToString(Player.Variable(score)) to text of Text

Action
Reset Timer[/code]

When you say two players do you mean both playing at the same time like in Bubble Bobble or alternating like Mario and Luigi in SMB? If the players are never on screen at the same time then one text object is all you should need.

@ddabrahim Thanks, I haven’t come across linked objects yet, so will give that a try. Sounds like a good solution though. I was keeping track of score via a variable on the text object, but your suggestion makes more sense :smiley:

@MattLB Players take turns, but both scores are always visible all the time. Think of a card game, but with scores :wink:

Here’s an example I was using to test this, and it works great. Adding here in case it helps others in future.
My project.zip (3.36 KB)