Solved-How to condense 'is X or Y or Z buttons pressed' conditional branches into one through script

Discussion in 'Learning Javascript' started by dragoonwys, Apr 18, 2019 at 1:00 AM.

Thread Status:
Not open for further replies.
  1. dragoonwys

    dragoonwys Freelance Illustrator Veteran

    Messages:
    290
    Likes Received:
    583
    Location:
    Malaysia
    First Language:
    english
    Primarily Uses:
    RMMV
    Hi there! Context, I'm trying to make http://yanfly.moe/2015/12/03/yep-36-map-gold-window/ this window appear and disappear whenever the character moves or stops in place. Unfortunately I don't know how to do that directly as an extension to the code yet so I am using in editor events instead.

    I have this parallel event that involves checking if the character is moving in any direction, if they are moving it will call on the plugin command that opens the window, if not, it will call on another plugin command to close it.

    I know I can do it by having multiple Conditional branches, 'if left button is pressed' etc, but I was wondering how I can condense this into one working if statement via script (I think it involves Input.isPressed? I'm sorry, this is one of the lines I found in the core that has to do with buttons. Not the a lit bulb with this yet. ^^') and use || between the 4 buttons, instead of having 4 conditional branches that pretty much do the same thing after its confirmed that the player is or not moving.

    Can someone point me to the right direction on how this is done, or if there is a better way of doing this? Should I scrap the entire idea of using events and it's more efficient to code an extension? Thank you.
     
    #1
  2. Silva

    Silva Scoobityboo Veteran

    Messages:
    197
    Likes Received:
    83
    First Language:
    English
    Primarily Uses:
    RMMV
    There is a script that checks if the player is moving
    Code:
    $gamePlayer.isMoving()
    If that doesn't work the way you want and you want to use the key is pressed method you could use this
    Code:
    Input.isPressed('left') || Input.isPressed('up') || Input.isPressed('right') || Input.isPressed('down')
    The || functions as the word 'or' and checks each condition individually and if one of them is true then the whole thing is true. If in the future you're looking for the 'and' method you can use &&
     
    #2
    dragoonwys likes this.
  3. dragoonwys

    dragoonwys Freelance Illustrator Veteran

    Messages:
    290
    Likes Received:
    583
    Location:
    Malaysia
    First Language:
    english
    Primarily Uses:
    RMMV
    @Silva
    Ahhh I see! Thank you very much for pointing that out.
    I see what I was doing wrong, I placed the || in the wrong place and now it works. I'll be using the .isMoving script since I like the format better, thank you for explaining everything! ^o^
     
    #3
    Silva likes this.
  4. slimmmeiske2

    slimmmeiske2 Little Red Riding Hood Moderator

    Messages:
    4,834
    Likes Received:
    3,840
    Location:
    Belgium
    First Language:
    Dutch
    Primarily Uses:
    RMXP

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

     
    #4
Thread Status:
Not open for further replies.

Share This Page