Home AMX User Forum NetLinx Studio
Options

Button.holdtime ??

Greetings,

Has someone some experience with the BUTTON.HOLDTIME data object?

What part of a button event could it be used in?

In the HOLD: it would seem that it could be used to increment a variable as the button is held??
HOLD:
    {
    nVARIABLE=BUTTON.HOLDTIME
    }
Seems awful processor intensive.
RELEASE:
    {
    nVARIABLE=BUTTON.HOLDTIME
    }
Seems like not the right place to put it.

Thanks

Comments

  • Options
    viningvining Posts: 4,368
    mpullin wrote in another thread:
    To be fair, I come from a computer programming background and NL timelines don't represent any classical data structure so that could have something to do with why I can't stand them.

    Your changed rate of holding & repeating can be accomplished via HOLDTIME btw.
    Code:
    BUTTON_EVENT[arrTP,butBUTTON]{
    PUSH: PULSE[dvDEVICE,1]
    HOLD[5,REPEAT]: if(BUTTON.HOLDTIME % 10 == 0 || BUTTON.HOLDTIME > 50) PULSE[dvDEVICE,1]
    }This code will pulse every second until 5 seconds have passed, then it will pulse twice a second.

    This is a very simple yet efficient way to do variable hold and repeats. Just like an alarm clock or radio button where you hold the button down and the time advances slowly but keep holding, say after 5 seconds it starts to advance faster.

    I originally did this variable hold-n-repeat via a time_line cuz I didn't know button.holdtime existed, although I'm sure I glanced over a million times but matt posted this just a few weeks ago and in one line it does what 10 lines or more did via the time_line.

    And I thought I was clever when I created the time_line version. Oh well, live and learn!
  • Options
    RELEASE:
        {
        nVARIABLE=BUTTON.HOLDTIME
        }
    

    Well, the holdtime will always be 0 in the release - 'cause if you release the button, it's not longer hold ;)

    One more solution if you need to do some action if button was hold long or short:
    DEFINE_VARIABLE
    INTEGER nFlag
    
    DEFINE_EVENT
    BUTTON_EVENT[dvPanel,1]
    {
    HOLD[50]:
    {
    nFlag = TRUE
    // do action if button was hold for 5 seconds
    }
    RELEASE:
    {
    IF(nFlag)
    {
    // button was hold less than 5 seconds
    }
    nFlag = FALSE
    }
    }
    
    I'm missing a EVENT_VAR - a variable which is usable within the whole event (similar to a LOCAL_VAR / STACK_VAR within i.e. the PUSH section) ;)
Sign In or Register to comment.