jmorris644
Active Member
Here is a copy of the sample that is in the API document:
Adding special actions to UPB, ALC, compose switches
var swHist = Array(); // Initialize array, put at top of script
function onUPBSwitch(swtch, unit) { // Callback called by haiku when a unit’s switch is pressed
// Is it the second time the switch was pressed in a row?
if(swHist[unit] != null && swHist[unit] == swtch) {
if(swtch == 1) { // Lets check if the on switch was pressed twice
// Take the alert line out if you don’t want the pause in between because
// HaikuHelper will wait for the alert to be dismissed before continuing
alert('unit ' + unit + ' was tapped ON a second time!');
controller.unitWithNumber(unit).off(); // Lets do something special
}
swHist[unit] = null; // Clear to prevent repeated second press behavior
} else {
swHist[unit] = swtch; // Store the switch that was pressed on the unit
}
}
I was expecting that with this code I could turn a specific switch on 2 times in a row and it would execute the action. It does. However, if I turn the switch on, then use another switch, then turn the 1st switch on again it still activates the code.
This isn't really the desired action. At least not for me. If I use a different switch in-between the actions of the first switch I would want the array for the first switch to go to null.
So, other than adding a loop to Nullify all of the non-activated switches, is there any other way to achieve the function that I am looking for? It seems that a loop is rather cludgy as the total number of switches can change which means I would have to keep the loop count manually updated.
I hope this made some sense
Joe
Adding special actions to UPB, ALC, compose switches
var swHist = Array(); // Initialize array, put at top of script
function onUPBSwitch(swtch, unit) { // Callback called by haiku when a unit’s switch is pressed
// Is it the second time the switch was pressed in a row?
if(swHist[unit] != null && swHist[unit] == swtch) {
if(swtch == 1) { // Lets check if the on switch was pressed twice
// Take the alert line out if you don’t want the pause in between because
// HaikuHelper will wait for the alert to be dismissed before continuing
alert('unit ' + unit + ' was tapped ON a second time!');
controller.unitWithNumber(unit).off(); // Lets do something special
}
swHist[unit] = null; // Clear to prevent repeated second press behavior
} else {
swHist[unit] = swtch; // Store the switch that was pressed on the unit
}
}
I was expecting that with this code I could turn a specific switch on 2 times in a row and it would execute the action. It does. However, if I turn the switch on, then use another switch, then turn the 1st switch on again it still activates the code.
This isn't really the desired action. At least not for me. If I use a different switch in-between the actions of the first switch I would want the array for the first switch to go to null.
So, other than adding a loop to Nullify all of the non-activated switches, is there any other way to achieve the function that I am looking for? It seems that a loop is rather cludgy as the total number of switches can change which means I would have to keep the loop count manually updated.
I hope this made some sense

Joe