Script for MIDI out toggle on button press?

I'm reprogramming the "select" buttons on my APC40mkII to include some groups of projection zones, using code similar to the following:

ToggleSelectZone 1,2,3,4,5,6,7
FocusZone 1
Exit

The buttons are selecting the projection zones as expected. However, I would like to include MidiOut code to toggle the light on and off on the APC40mkII button. How can I do this?

Additionally, I would also like to program some main grid buttons on a second APC40mkII to turn on QuickFX. I have figured out how to program the buttons to select the QuickFX. But, I know the code should be different here for toggling the state of the button light, since it won't just toggle on and off with the button press, but will also need to turn off if another button is pressed.

I'm sorry if this is unclear. I'm just learning PangoScript. I've found MidiOut and understand that. I just don't know how to tell it "If this button is pressed, send this midi out command, and if the button is pressed again, or another button is pressed, then send this other midi out command."

I want the lights to go on and off based on the UI button state, rather than the zone state, because I'm using some zones in more than one select "group" and doing it by zone state makes other select buttons that include that zone light up.

Then, my script works to turn on the light. But, it doesn't turn off the light on the second button push. What am I missing? Any scripting masters who can help me fix this?

I can't tie the state of the light to the state of the zones because I have several zone group selects, many of which contain some of the same zones. If I tie the light to the state of the zones, it turns on all lights for each button that includes those zones. I need to tie the state of the light to the button push on the controller.