VisualPinball / VisualPinball.Engine.Mpf

Mission Pinball Framework support for VPE
MIT License
0 stars 1 forks source link

Unmapped MPF switch #21

Open arthurkehrwald opened 2 months ago

arthurkehrwald commented 2 months ago

On startup, MPFGameLogicEngine logs a warning like this for each switch: VisualPinball: VisualPinball.Engine.Mpf.Unity.MpfGamelogicEngine|Unknown intial switch name "s_flipper". Whenever a switch is pressed, an error like this follows: VisualPinball: VisualPinball.Engine.Mpf.Unity.MpfGamelogicEngine|Unmapped MPF switch s_flipper

This is because the _switchIds dictionary in MpfGameLogicEngine is never populated. This bug was introduced by pull request #11, that deleted the line in the MpfGameLogicEngine.OnInit function that added the switches to the _switchIds dictionary without any replacement. Later, when a switch changes state, and the MpfGamelogicEngine.Switch is called, the ID of the switch in question cannot be found in the _switchIds dictionary, because it is empty.

Moreover, MPF needs the ID to identify the switch, but it was deleted in pull request #408 in the main VPE repository. If the name of the switch is passed to the function MpfApi.Switch, the switch does no light up green in MPF when pressed. It only works with the ID. Same probably goes for coils and lamps, but I have not tested those. The MPF documentation says a number is required for each switch:

The following sections are required in the switches: section of your config: number: Single value, type: string. Defaults to empty. This is the number of the switch which specifies which switch input the switch is physically connected to. The exact format used here will depend on which control system you're using and how the switch is connected.