I'm finding this very slow going, and would appreciate some tips to help me understand one or two issues.

I have a very simple menu:
Code:
	menu = SimpleMenu("menu",
		{	
		})

		menu:addItem({
			text = self:string("SQUEEZEEXT"),
			style = 'item_choice',
			iconStyle = "digital",
			check = Choice(
				"choice", 
				{ "On", "Off" },
				function(obj, selectedIndex)
					log:info(selectedIndex)
				end,
				2
			)
		})
This creates a simple one-line menu item that toggles between 'On' and 'Off'. It starts with 'Off' (as given by the index value of 2). 'selectedIndex' is logged to the terminal, and I can see that it corresponds to the currently selected value.

What I'd like to know is whether it's possible to set the choice to 'On' or 'Off' programmatically, from within the callback function. In my intended code I'd like to call some code when 'On' is selected, which may or may not succeed - if it doesn't succeed, then I'd like to revert to 'Off' again, programmatically (*see below for the reasoning).

The Jive Lua source code conventions page in the wiki says that 'setSelectedIndex' can be used for this, and that doing so will call the callback function again.
Code:
-- New choice with options On and Off, Off is selected
local choice = jive.ui.Choice(
       "choice", 
       { "On", "Off" },
   function(object, selectedIndex)
           print("Choice is " .. tostring(selectedIndex))
   end,
       2
)

-- Change checkbox state
choice:setSelectedIndex(1)
I have all sorts of problems with this.
1) The sample code above uses the word 'choice' in a couple of places ('local choice =', "choice") and it's not clear to me which instance is the one referred to by 'choice:setSelectedIndex'. So in my own code at the top, should I use 'check:setSelectedIndex' or 'choice:setSelectedIndex'? Neither seems to work.
2) If setting the selected index from within the function calls the callback function again, it seems like this could go on forever. If I can't set the index from within the callback function, where else can I set it? My menu is set up inside 'function setupJogglerSqueezelite(self, menuItem)' - this sets up the menus once when the window is loaded, and thereafter the menus operate autonomously. It's the result of selecting a menu item that I want to act on.


*What I'm trying to achieve:
I'm trying to start squeezelite on an external USB device. I can list the devices, and select from them as a Radio Group. The problem is that when I attempt to start squeezelite on some of the listed devices it won't start (e.g. on surround21, surround41, surround51). I can detect those cases, but the menu item displays 'On', since it was toggled from 'Off' when I selected it in order to try to start squeezelite. So in the cases where squeezelite fails to start I'd like to programmatically toggle the menu back to 'Off', so that it's clear to the user that squeezelite didn't start. I'm also trying to put up a popup message when that happens - see my other question about popup messages not disappearing after the specified time - honestly, trying to program in Jive/Lua, with very little experience in this type of language, has been like pulling teeth!