Hello. Lets say I have a BaseInputDelegate, and a Submenu with its own Delegate, which in Monkey C, each have to be separate classes. Lets say I want the Submenu to adjust a variable that will be used in the rest of the regular BaseInputDelegate. Do I need to use a global var or can I somehow use some tricky programming logic to accomplish this?
The separation in the classes makes me think that it is impossible to somehow do it, without the use of a global variable. Please explain if there is another way! thanks!
var gSelectButtonLocked; // do I really need this, or is there a better way?
class BaseInputDelegate extends WatchUi.BehaviorDelegate
{
function onSelect() {
if (gSelectButtonLocked!= true) { // if buttons are unlocked
// process normal Select button functionality, i.e., start or stop activity
}
}
function onMenu() {
var menu = new WatchUi.Menu();
var delegate;
menu.setTitle("My Menu");
menu.addItem("Lock Buttons", :one);
menu.addItem("Another Option", :two);
delegate = new MyMenuDelegate();
WatchUi.pushView(menu, delegate, WatchUi.SLIDE_IMMEDIATE);
return true;
}
} // end of class BaseInputDelegate -----------------------------------
class MyMenuDelegate extends WatchUi.MenuInputDelegate {
function onMenuItem(item) {
if (item == :item_1) {
System.println("User wants to lock buttons");
gSelectButtonLocked = !gSelectButtonLocked;
} else if (item == :item_2) {
System.println("Item 2");
}
}
} // end of class MyMenuDelegate --------------------------------------