High Score Slide MPFTextInput Question

105 views
Skip to first unread message

Nixco

unread,
Aug 15, 2025, 6:49:18 AMAug 15
to MPF Users
Hi,  good day to you all !

I noticed that during High Score mode / slide, when at least 2 players have to enter their initials, - MPFTextInput -  doesn't reset the - RichTextLabel - value between each player entry.

Secondly, I have a question regarding the High Score Slide.

I created a mode that allows players to enter their names before starting their first ball.

The names are stored in variables : 

player_one_name
player_two_name
...

I didn't find a way to use / send those values in High Score Mode as --> score(player_num)_name

so that you do not have to enter your initials a second time.

I have attached the files if you want to test.

Any idea ? :D





player_one_naming.yaml
player_two_naming.yaml
player_one_naming.tscn
high_score.gd
high_score.yaml
player_two_naming.tscn
high_score.tscn

Alex L

unread,
Aug 15, 2025, 6:41:08 PMAug 15
to MPF Users
I've been digging in the high score python code recently, so I might have something that could work for you --

No promises, but in the current implementation if the Player object has an "initials" value set, it appears that it will skip the code that opens the godot slide and prompts for entry.

You might be able to hack this value by using a player variable named "initials" and an event sometime during your game that populates your existing variable value into this name, or else you will need to write a custom python hook to copy it over instead.

Do note that if you manipulate this Player.initials value yourself, you're somewhat reaching into the private internals of MPF, and there is no guarantee that future versions of MPF will not break this workaround (say, by changing the name or storage type of this data).

Samuel Chauviere

unread,
Aug 19, 2025, 7:38:42 AMAug 19
to MPF Users
Hello,

I opened an issue about this a few days : https://github.com/missionpinball/mpf-gmc/issues/31

Samuel

Alex L

unread,
Aug 20, 2025, 2:23:23 AMAug 20
to MPF Users
I reproduced the same behavior in my codebase, and made a PR with a fix that worked for me https://github.com/missionpinball/mpf-gmc/pull/33

Nixco

unread,
Sep 1, 2025, 8:58:33 AMSep 1
to MPF Users
Hello !

Sorry for the late answer.
Thank you alex for the fix, it's working like a charm :D

Regarding the player.initials, i changed a few things in my code. 
Each name is stored in a player variable --> player_name
Names are displayed correctly in Godot with current_player.player_name

I tried this in high_score.py, but the return value is null. As i'm not a coder i'm not sure where to handle this.

                    if not player.initials:
                        try:
                            player.initials = self.machine.log.info(player["player_name"])
                            #player.initials = await self._ask_player_for_initials(player, award_names[i],
                            #                                                      value, category_name)

On a second thought, i tried to pre-fill a "MPFVariable" that display "MPFTextInput" with the player_name value. But i couldn't get it to work.
I think it would be the best way to do it, so the player has the freedom to chose either to change or keep his name.

Would you have any idea for this ?

Thanks !

Alex L

unread,
Sep 1, 2025, 5:22:34 PMSep 1
to MPF Users
"self.machine.log.info(<some text>)" is how you print information out to the logs (but it does not then return the text value). You can just directly assign `player.initials = player["player_name"]` instead.

If you want to provide the name as the slide default, you're going to need to override some code in the definition of "_ask_player_for_initials" so that
the event "high_score_enter_initials" provides the name, and then you're going to need to add a new behavior in the high score Godot slide that receives
that value and somehow sets it as the initial value for the control (probably to the MPFTextInput node, maybe also RichTextLabel node. Possibly requiring modifications in the mpf_text_input.gd script file.)

It's doable, but it will also make more of your game code diverge from the standard MPF and GMC installs, so you will have to maintain all of these customizations whenever you upgrade versions.

The way I would do this to avoid needing any MPF or GMC customization at all is to just store the name value in a player variable named "initials" from the start. Then there is no need to override MPF python behaviors because the guard "if not player.initials" will immediately just work. But this also wouldn't support the ability to override later.

Nixco

unread,
Sep 2, 2025, 7:09:00 AMSep 2
to MPF Users

I followed your recommendation and changed the variable 'player_name' by 'initials'. Everything is working fine with this solution.

But as we're not entering this statement anymore, i found an issue with my logic

                    if not player.initials:
                       ...

this function isn't called

 self._ask_player_for_initials

So i can't use the "high_score_enter_initals" event anymore.  I use it to send a method in Godot and display an animation for each player. 

#high_score.yaml
slide_player:
    mode_high_score_started:
        high_score:
            action: play
    high_score_enter_initials{player_num==1}:
        high_score:
            action: method
            method: highlight_player_1

# high_score.py
self.machine.events.post('high_score_enter_initials',
                                 award=award_label,
                                 player_num=player.number,
                                 value=value)

I tried to add something like this to have a second choice (there is or isn't something in the player.initials variable) and then a second event.

                    # don't ask player for initials
                    if player.initials != "":
                        self._dont_ask_player_for_initials(player, award_names[i],
                                                            value, category_name)

    async def _dont_ask_player_for_initials(self, player: Player, award_label: str, value: int, category_name: str) -> str:
        self.machine.events.post('high_score_display',
                                 award=award_label,
                                 player_num=player.number,
                                 value=value)

        await asyncio.sleep(self.high_score_config['award_slide_display_time'] / 1000)

But it seems i can't send " high_score_display" this way. Do you think it is doable in any way ?

Thank You !

Alex L

unread,
Sep 2, 2025, 4:00:41 PMSep 2
to MPF Users
So if you look through the high score py file, the `if not player.initials` is just a guard around sending the `high_score_enter_initials` event, which is intended to signal that a player needs to enter initials.
Then later on there is a call to `self._show_award_slide`. That function posts more events (though in the newest version of 0.80.x all but the one I mention next are going away) -- most interesting to us is the line:

```
self.machine.events.post('high_score_award_display', player_name=player_name, award=award, value=value)
```
I suggest that the animation you want to play should be triggered off of this event ("high_score_award_display"), and then you probably will not need to make any changes in the high_score.py at all.

Note that this slide is given a default of 4 seconds to display, and you can change the setting `award_slide_display_time` to something else based on your animation length.

Nixco

unread,
Sep 8, 2025, 9:50:53 AMSep 8
to MPF Users
There is a difference between 
"high_score_enter_initials" and "high_score_award_display"

I can't collect the player number with the second event.

So i added 
player_num=player_num,

in
        self.machine.events.post(
            'high_score_award_display',
            player_num=player_num,
            player_name=player_name,
            award=award,
            value=value)


And everything is working well !

Thank you for all your advices :D
Reply all
Reply to author
Forward
0 new messages