Long press button

I've got a button that "when touch is pressed" it performs a behavior. I want to use the same button to initiate a behavior when it is pressed for 3 seconds or longer. Anyone know how to achieve this? I tried several things but the 1st rule gets initiated when I don't want it too.

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    I haven't tried it but I'm thinking you could do something like this:

    When touch is inside (the button)
    
    Timer After 3 seconds (don't click 'run to completion')
    
    Run your behaviors...
    
  • allc1865allc1865 Member, PRO Posts: 777

    The only thing I can think of is to make whatever behavior you want to perform, say, a bullet to shoot, a boolean. So you'd say when touch is pressed > (using a timer rule) after 3 seconds > run to completion > change attribute > game.bullet to true.

    I made a template to show what I mean using an quick & easy appearing block actor when touch is pressed after 3 seconds.
    https://www.dropbox.com/s/npv11nihwal9z3j/appearing actor.zip

    Hope this helps! ;):)

  • sawkasteesawkastee Member Posts: 184

    The first rule still runs...hmmmm. There's got to be a way to keep the first, when touch is pressed rule from running.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Try this:

    When touch is pressed
    .....change attribute self.touchTime (real) to self.Time
    .....When self.Time > self.touchTime+3
    ..........[behavior you want to occur]
    Otherwise
    .....change attribute self.touchTime to 999999
    

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2014

    @tatiang said:
    Try this:

    When touch is pressed
    .....change attribute self.touchTime (real) to self.Time
    .....When self.Time > self.touchTime+3
    ..........[behavior you want to occur]
    Otherwise
    .....change attribute self.touchTime to 999999
    

    Isn't this the same as . . .

    When touch is pressed

    Timer, after 3 seconds . . .

    ?

  • SocksSocks London, UK.Member Posts: 12,822

    @sawkastee said:
    The first rule still runs...hmmmm. There's got to be a way to keep the first, when touch is pressed rule from running.

    It's impossible, not just technically impossible in GameSalad, but logically impossible.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2014

    @‌Socks

    @Socks said:
    Isn't this the same as . . .

    Hmm, yes I suppose it is. Lol... I need more sleep.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822

    @tatiang said:
    @‌Socks

    Hmm, yes I suppose it is. Lol... I need more sleep.

    :smile:

  • sawkasteesawkastee Member Posts: 184

    Ok, I guess I'll just think of another way to do this without a long press.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @sawkastee said:
    Ok, I guess I'll just think of another way to do this without a long press.

    You have two solutions for one question and you're giving up? Did you try either of them?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    edited April 2014

    @Socks said:Isn't this the same as . . .When touch is pressed Timer, after 3 seconds . .?

    Yeah, but @tatiang‌ just wanted to make it sound a little smarter and complex. ;)

  • SocksSocks London, UK.Member Posts: 12,822

    @Braydon_SFX said:
    Yeah, but tatiang‌ just wanted to make it sound a little smarter and complex. ;)

    He should've used tables + trigonometry + modulus and the word 'flappy' at least 3 or 4 times.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2014

    @tatiang said:
    You have two solutions for one question and you're giving up? Did you try either of them?

    Neither of them address the whole question, they both just address the 'after 3 seconds something happens' part, he also wants something to happen when the button / actor is first touched ('when touch is pressed'), but that initial action doesn't happen when you go for the 'after 3 seconds' option . . . . . like I say it's impossible (logically impossible) as 'when touch is pressed' will always trigger whether you press the button very briefly or whether you hold it for 3 seconds.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2014

    @sawkastee said:
    Ok, I guess I'll just think of another way to do this without a long press.

    You could drop the 'when touch us pressed' part and make that 'when touch is released'.

    So, the first rule gets initiated when the player releases the button after having pressed it, but if they hold it for 3 seconds or more the second rule gets initiated instead.

    ?

  • sawkasteesawkastee Member Posts: 184

    @tatiang
    I tried them both and they didn't work. @Socks I also tried the "when touch is released", it works the best but I'd like to see "when touch is pressed" so I don't have the slight lag of waiting for the button release.

    I want an implementation similar to that of an iOS app icon. If you touch, it opens the app, but when you touch and hold the app icon jiggles so you can move them. In my app the touch would go to the next card and touch and hold would open a settings menu.

  • AdrenalineAdrenaline Member Posts: 523

    That would be "when touch is released" then. Even iOS can't possibly know your intention (to just tap, or touch and hold) before you actually complete the action.

  • AdrenalineAdrenaline Member Posts: 523

    If it's still not working as intended, try starting a timer when the user initiates the touch. Then, on release, check the length of time that the button was touched. If it's less than 3 seconds, go to the next card. If it's 3 seconds or more, open the settings menu. This way, only one of those behaviors can fire at a time.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Try something like this:

    When (All)
        touch is pressed
            Change Attribute: self.StartTime To: self.Time
                When (All)
                    self.Time > self.StartTime + 3
                        (Open Settings Menu)
    
    When (All) 
        touch is released
        self.Time < selfStartTime + 3
            Change Scene
    
  • sawkasteesawkastee Member Posts: 184

    @RThurman said:
    Try something like this:

    When (All)
        touch is pressed
            Change Attribute: self.StartTime To: self.Time
                When (All)
                    self.Time > self.StartTime + 3
                        (Open Settings Menu)
    
    When (All) 
        touch is released
        self.Time < selfStartTime + 3
            Change Scene
    

    Works! Thanks!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Glad its working for you! You are welcome.

Sign In or Register to comment.