Python to switch visibility between multiple objects (game engine)
Lets dig a bit deeper in the requirements and look how it fits your design (or find a better one):


You have a set of (ordered) objects = a list.
You want one and only one object be (lets say) "selected" at any moment
You want be able to select the next while deselecting all others.


Open Question: What should happen when the last object is already selected?



As there is always one object selected I suggest to use a token that indicates what object is selected.

This means you need a separate object as token. When you want to know what object is selected ... ask the token. If you want to select another object ... request it at the token.

This answers your question 2


  Where should this script reside, along with the M and N controllers? Should it be attached to the cube, or to some empty object somewhere? Or is it going to have to be multiple scripts?
  -> the token does that.


Token

So lets have a closer look at the token.


It needs to know what object is selected. 


We need a storage for a single game object at any time.
We need to be able to provide the selected object when asked 

It should be able to select the next object in a list of objects


We need an ordered list of selectable objects (when performing this operations)



Lets look at a possible implementation of the token.

How you get your list of objects is up to you (e.g. you could look for objects with a specific property and order by property value). So I assume you implemented a function called getSelectables(). The following snippet contains a dummy implementation:

selection.py

import bge

#--- BGE callables
def next():
    if not allSensorsPositive():
        return

    deselectAll()

    next = findNext()
    select(next)


This is indeed not much. First (as any BGE code) check the sensors' status.
Then deselect all selectable tokens. If you load them unselected, you can just deselect the current selected object deselect( getSelected() ).

Then find the next object and select it.

I hope you find this is what you want.

How to use it:

First you should select one object at startup. There is no special operation for that (you could if you want). So we simple call next():

Always sensor [no level triggering]
   ---&gt; Python controller Module: "selection.next"




This will deselect all selectable objects and select the first one after loading the scene.

To select the next selectable object we call next() too:

Event sensor [no level triggering]
   ---&gt; Python controller Module: "selection.next"




Please note, next() does not do anything when not all sensors are positive. Therefore you can't connect both sensors to the same controller. 

Why is it that way?
Imagine you want to deactivate the ability to call next(). In this way you can connect another sensor that controls the activation:



You tried that? I hope you noticed the code is not complete. If you want you can try to implement your own version. But here are the details that can help you.

selection.py continued ...

#--- internals

INTERNAL_PROPERTY_SELECTED_OBJECT = "_internal.selectedObject"

def deselect(object):
    object.visible = False

def select(object):
    getOwner()[INTERNAL_PROPERTY_SELECTED_OBJECT] = object
    object.visible = True

def deselectAll():
    for selectable in getSelectables():
        deselect(selectable)

def findNext():
    selectables = getSelectables()
    selected = getSelected()
    try:
        nextIndex = selectables.index(selected) + 1
    except ValueError:
        nextIndex = 0

    return selectables[nextIndex % len(selectables)]

def getSelected():
    return getOwner().get(INTERNAL_PROPERTY_SELECTED_OBJECT)

def getSelectables():
    'Implement your own object list'
    objects = bge.logic.getCurrentScene().objects
    return [objects[name] for name in 
            ["Cube", "Sphere", "Cylinder"] ]

#--- internal utilities
def allSensorsPositive():
    for sensor in bge.logic.getCurrentController().sensors:
        if not sensor.positive:
            return False
    return True


def getOwner():
    return bge.logic.getCurrentController().owner


Here you see that selection/deselection actively changes the involved objects (setting visibility). When selecting the object running this code will store the selected object in a property replacing any previous selection.

Finding the next selectable object is simply looking at the list and grab the next one by index. If the current selection can't be found, it the first one gets picked. If the last one is selected ... it starts with the first one again nextIndex % len(selectables). If you do not want that you change that code to min(nextIndex, len(selectables)-1).

As said earlier you should implement your own version on getSelectables().

The utility functions are often used and would live happily in a common module. They are here to complete this snippet for you.

As homework you might want to implement a previous() function.

I hope it helps you

Edit: I forgot to answer your other questions:


  How do I change the visibility of multiple objects (perhaps using the object name) from one script?


Either each object doe it by itself (e.g. via Visibility actuator), or you let the object do it by itself via KX_GameObject.visible (see snippet above)


  If it has to be multiple scripts, how does the variable V get initialized properly, and how does it get globally recognized by all the different scripts?


Variables are always local to the code. You could create a module variable that is a singleton with the module. The above solution uses a property of the selecting object. This means you can have different selecting objects each with own selection (I guess this is not what you want).

If you want to know if an object is selected or not you have to ask the selecting object. Alternative, you can check if the selectable object is visible or not.