How to check for input.press? for a period of time? (holds a key)

Discussion in 'Learning Ruby and RGSSx' started by KingHazeel, Jun 12, 2019 at 2:06 PM.

  1. KingHazeel

    KingHazeel Veteran Veteran

    Messages:
    94
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMVXA
    Basically I wanted to put in a script command where if the user presses a key once (trigger) one action is performed, but if they hold the key (press), a different action is performed. When I attempted this, however, the "input.press?" option always took priority over the "input.trigger?" action, no matter how quickly I was pressing the key. Is there a way I can check if the player is pressing the key for say, 1-3 seconds, and then triggering the action if this condition is met?
     
    #1
  2. ShadowDragon

    ShadowDragon Veteran Veteran

    Messages:
    122
    Likes Received:
    43
    Location:
    Netherlands
    First Language:
    Dutch
    Primarily Uses:
    RMMV
    you can put the seconds into a variable and make the

    wait for 60 frames
    add +1 variable,
    Conditional brance : script: key press here
    (condition brance) if variable is >= 3
    do stuff
    else
    reset variable = 0
    end

    around this can work out in a common event if you call it
     
    #2
    Bex likes this.
  3. KingHazeel

    KingHazeel Veteran Veteran

    Messages:
    94
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMVXA
    Is there a direct way to script it? I suppose I could try to work it into a common event, but the problem I see with this is that even if I set a common event to be a parallel process, it wouldn't behave in such a way if it were called outside of setting the switch on. ...Although maybe I can quickly set the switch on and off in the script...
     
    #3
  4. Bex

    Bex Veteran Veteran

    Messages:
    1,006
    Likes Received:
    205
    First Language:
    German
    Primarily Uses:
    RMMV
    Shadow Dragon posted a good Idea, but it seems not fluid enough with a 60 Frames wait.
    Maybe you could try another solution without the long wait.
    I made one in MV but it works in VX-Ace, you just need someone who makes a Script out of it, because its Evented with standard Editor.

    Event on Paralell with Eventcode:
    Code:
    ◆If:Button [Pageup] is pressed down
      ◆Control Variables:#0010 press down time = 0
      ◆Loop
        ◆If:Button [Pageup] is pressed down
          ◆Control Variables:#0010 press down time += 1
          ◆Wait:1 frame
          ◆
        :Else
          ◆Break Loop
          ◆
        :End
        ◆
      :Repeat Above
      ◆If:press down time ≥ 0
        ◆If:press down time ≤ 49
          ◆Text:None, Window, Bottom
          :Text:Normal Swordslash...
          ◆
        :End
        ◆
      :End
      ◆If:press down time ≥ 50
        ◆Text:None, Window, Bottom
        :Text:Powerattack! ...
        ◆
      :End
      ◆
    :End
    
    If you keep holding the Button, a Variable will be increased until you release the Button, than the value is checked with conditional branches which than execute the wanted behavior. (If variable = 60 than you pressed the Button 1 Second)

    Edit: If you need additional behaviors implemented into this, let us know.
    Also this Thread is helpful with Script Calls for use inside Eventcommmands:
    https://forums.rpgmakerweb.com/index.php?threads/script-call-collection-for-vxace.25759/
    If you need a Script for Scripteditor, sorry i cant Script, maybe one of the Scripters drops by.
     
    Last edited: Jun 12, 2019 at 4:48 PM
    #4
  5. KingHazeel

    KingHazeel Veteran Veteran

    Messages:
    94
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMVXA
    It's the wait part that stumps me. I mean if I do that in a script, I'd get the error "can't yield from root fiber".
     
    #5
  6. Bex

    Bex Veteran Veteran

    Messages:
    1,006
    Likes Received:
    205
    First Language:
    German
    Primarily Uses:
    RMMV
    Maybe i got another Solution without wait.
    The following solution doesn't use extra wait, so it should not interrupt your script loop.

    I hope the code is self explanatory, else just ask.
    Code:
    ◆If:Button [Pageup] is pressed down
      ◆Control Switches:#0001 Push Recogniced = ON
      ◆Control Variables:#0010 press down time += 1
      ◆
    :Else
      ◆If:Push Recogniced is ON
        ◆If:press down time ≥ 0
          ◆If:press down time ≤ 49
            ◆Text:None, Window, Bottom
            :    :Normal Swordslash...
            ◆
          :End
          ◆
        :End
        ◆If:press down time ≥ 50
          ◆Text:None, Window, Bottom
          :    :Powerattack! ...
          ◆
        :End
        ◆Control Variables:#0010 press down time = 0
        ◆Control Switches:#0001 Push Recogniced = OFF
        ◆
      :End
      ◆
    :End
    Edit:
    Here a version without Switch with only 1 Variable.
    Code:
    ◆If:Button [Pageup] is pressed down
      ◆Control Variables:#0010 press down time += 1
      ◆
    :Else
      ◆If:press down time ≥ 1
        ◆Comment:---------------------------------
        ◆If:press down time ≤ 49
          ◆Text:None, Window, Bottom
          :    :Normal Swordslash...
          ◆
        :End
        ◆If:press down time ≥ 50
          ◆Text:None, Window, Bottom
          :    :Powerattack! ...
          ◆
        :End
        ◆Control Variables:#0010 press down time = 0
        ◆
      :End
      ◆
    :End
    This is no ready scriptcode, this is copy pasted eventcode from mv.
     
    Last edited: Jun 12, 2019 at 5:56 PM
    #6
  7. KingHazeel

    KingHazeel Veteran Veteran

    Messages:
    94
    Likes Received:
    1
    First Language:
    English
    Primarily Uses:
    RMVXA
    Hey, it works! ...And yes, as you correctly predicted, this is for a charge attack. I should add an animation when it's fully charged, but I think I can do that on my own. Thanks!
     
    #7

Share This Page