Button Status for Conditionals
BenDerzGreat
Posts: 19
Hey Everyone,
Excuse me if this question is very obvious, but I couldn't find any previous info on here about it and was wondering before implementing it in my code. Is it possible to use a button status in a conditional statement for an event to determine what to do, for example if rooms should be combined. Would I use devchan pairs? could i use on/off or do i need a variable to track it?
for example:
if([dvTP,1] = ON)
{
// do something
}
else
{
// do something else
}
Excuse me if this question is very obvious, but I couldn't find any previous info on here about it and was wondering before implementing it in my code. Is it possible to use a button status in a conditional statement for an event to determine what to do, for example if rooms should be combined. Would I use devchan pairs? could i use on/off or do i need a variable to track it?
for example:
if([dvTP,1] = ON)
{
// do something
}
else
{
// do something else
}
0
Comments
I agree that tracking it against a variable would be more effective and less error prone. But how would I update the status of the variable based on the status of the button?
But, as an intellectual exercise:
You could also use a channel event.
channe_event[TP,1]{
on:{
My_Button_State=1;
// do something
}// on
off:{
My_Button_State=0;
// do something else
}// off
}// chennel event
In fact, I've long though AMX broke it's own rule with Faders.
I've always thought there should be Level_Events and Fader_Events. The Fader_Event should be for user interaction only and the Level_Event is for feedback only. (Similar to a Button_Event and a Channel_Event on a UI. Never mind that we still kind of break that rule by using Chanels for both actions and feedback on devices. Oh well...
You are only to get that channel event from a touch panel if you first set the feedback in code - speaking of dog wagging tails...
Yeah, that's the power of Hungarian notatition... :-) But as long as you use that, there can be an advantage to immediately see that the variabele is meant to only hold two states.
BUTTON.INPUT is a devchan though isn't it? What does 1 - [BUTTON.INPUT] resolve to? Never seen that notation before.
Paul
Its a devchan, just like you said
In the case shown it will resolve to a toggle - on or off depending on the feedback state (on = 1 and off = 0) of the button.
Paul
Any time I can use math to my advantage I will - Here's a chunk of code that sends lighting to either full or off depending on what the user is expecting based on button feedback...
Here I prefer to just reference the button toggle state, because it makes the lights follow the behavior of the button the user expects. The button is a toggle for zone lighting on and off, but the feedback changes when the lights hit their preset values. If they're ramping from one to another, it doesn't change until it hits its final. So here, the feedback changes locally on button press(other panels in the room do not change until preset value is reached), but if they hit the button by mistake, a second button press will evaluate to turn them back on before the ramp is completed...
In some respects the devchan datatype can be considered at the native boolean data type in NetLinx (and all the way back to AXcess when I first started using it in that context... setting channels on serial devices to track true false values was always my favorite )
Paul