Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Player Score Widget (MPFVariable Question)

56 views
Skip to first unread message

Owen Underwood

unread,
Feb 11, 2025, 6:30:00 PMFeb 11
to MPF Users
Hello,
I am trying to create a reusable "player score widget" for each player (whenever a new player is added, create a new score widget and link it to that player's score).
I am having some issues trying to connect the variable in Godot with playerX score in mpf (the MPFVariable node within the score widget doesn't have a variable_type or variable_name assigned until after its created and I call a function).
I have a function (updateVars) in my scoreWidget where I try to assign the variable_name & the variable_type, but after draining a ball and moving to player 2, all scores are being added to the first player.

Ive attached what I think are the relevant Godot & config files.
- basev2 is the main overlay widget that creates & contains the player score widgets
- scoreWidget is the widget for a single players score
- game.yaml is my machine folder file is where I am sending the methods to Godot

I'd be happy to share my entire code base from GitHub, just let me know your username (its not public since I dont have the rights to a lot/any? of the assets).

Any help would be appreciated & thanks in advance
basev2.gd
basev2.tscn
game.yaml
score_widget.gd
scoreWidget.tscn
overlayWidget.tscn

Anthony van Winkle

unread,
Feb 12, 2025, 10:50:46 PMFeb 12
to MPF Users
As always with MPF there are a number of ways to do this, here are some ideas.

If the score widget you wish to show is only a score, then MPFVariable supports min/max players and can show and hide itself accordingly. If you want a more robust widget with score, player number, maybe a picture or some other text, make that your reusable widget/scene and put it under an MPFConditional node that uses min/max players to control its appearance. Alternatively, you could make the MPFVariable score your parent node (with min/max condition) and other elements (like player number or picture) children of the MPFVariable node, so they will also show and hide with it.

I would recommend putting all of your instances of the widget/scene under a single parent slide/widget that you can show or hide, if you want more control than just min/max players. I say widget/scene here because if it's persistent, or part of another slide or widget, then your reusable "player score" piece wouldn't have to be an MPFWidget, it could just be a regular Godot scene. It only needs to be an MPFWidget if you want to use widget_player to control it.

With this kind of setup, using the built-in min/max player properties of MPFVariable or MPFConditional, you shouldn't need to send any events from MPF to make the nodes show. And for example, if you want to not shot the widget for the current player, use an MPFConditional where current player number != the player number of the widget ought to do just fine.

Note that until last week there was a bug on MPFConditional related to min/max players, it's been fixed now so you'll want to pull the latest. You can read about Alan's slide setup in that thread: https://groups.google.com/g/mpf-users/c/RsWL_PRwBL8

Owen Underwood

unread,
Feb 12, 2025, 11:45:54 PMFeb 12
to MPF Users
Thanks Anthony, those are good suggestions and I will incorporate some of them.
I do have one issue thought that I cannot figure out. I dont think I did a great job explaining in my original post so I have attached some screenshots & explaining what I am doing while the game is running.

Step 1: Start a game (correctly creates the score widget)
1 - One Player.PNG


Step 2: Add a 2nd player (correctly adds a second score widget)
2 - Two Players.PNG

Step 3: Score some points as player 1 (correctly adds to the player 1 score)
3 - Player One scores points.PNG

Step 4: Drain player ones ball (correctly switches to player 2, there is some highlighting & red dot indicating which player is active)
4 - Player 1 Drains.PNG

Step 5: Score points as player 2 (this is where I have issues, the score is appearing in the wrong box)
5 - Player 2 scores points, but they are showing up in player 1.PNG

Its showing the right number of points for player 2, but they are appearing in the wrong place.

james cardona

unread,
Feb 14, 2025, 9:41:24 AMFeb 14
to MPF Users
I think you are making this more complicated then it needs to be. For my scoring, I just make 4 different MPFvariables and populate them as appropriate. The one thing I do is populate them as strings, not numbers so if there is only one player then player 2's score says "join now" and player 3 and 4 say " ". Once on ball 2, the "join now" goes away. This keeps everything on the MPF side, so to speak, so that is another way to do it.

Anthony van Winkle

unread,
Feb 14, 2025, 2:13:31 PMFeb 14
to MPF Users
It looks like maybe your P1 score widget is set to "Current Player" as the variable type instead of "Player 1". Though not sure what the P2 box is set to, because it should also show the player 2 score if the variable type is "Player 2" or the same if it's "Current Player"
Reply all
Reply to author
Forward
0 new messages