Conditional "Show Choices" (hide or disable choices)

Discussion in 'JS Plugin Releases (RMMV)' started by Aloe Guvner, Jun 27, 2018.

  1. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,596
    Likes Received:
    1,003
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Conditional "Show Choices"
    by Aloe Guvner
    Download Link
    (Instructions: click the link, then right-click the "Raw" button and click "Save Link As...")​


    Background:

    This plugin allows developers to set conditions directly in the "Show Choices" event command.
    These conditions can determine whether the choice is hidden or disabled.

    No scripting knowledge or plugin commands are required!
    Everything is done directly in the "Show Choices" event command, providing an intuitive and efficient way to increase the depth of your story-telling through more interesting choices.


    How to use:

    The conditions to hide or disable the choice are written directly into the choice.

    An example is shown below. In this example, the first choice is hidden if switch #1 is ON, and the second choice is hidden if variable #1 is greater than zero. The third choice does not contain any conditions.

    ExampleChoices.png

    ◆Show Choices:First Choice <<s[1]>>, Second Choice <<v[1] > 0>>, Third Choice (Window, Right, #3, #2)
    :When First Choice <<s[1]>>

    :When Second Choice <<v[1] > 0>>

    :When Third Choice

    :End

    The format of the conditions is:
    <<HIDE,DISABLE>>

    If the HIDE condition is true, the choice will be hidden.
    If the DISABLE condition is true, the choice will be disabled.

    To include only a HIDE condition, no comma is needed:
    <<HIDE>>

    To include only a DISABLE condition, a comma is needed:
    <<,DISABLE>>

    To include both a HIDE and a DISABLE condition, separate with a comma:
    <<HIDE,DISABLE>>


    Short-Hand Abbreviations:

    The following short-hand abbreviations may be used inside the conditions to make it easier to write conditions:
    s[x] --> Game Switch #x
    v[x] --> Game Variable #x
    a[x] --> Actor #x (database id)
    p[x] --> Party Member x (index, which starts at 0)
    t[x] --> Troop Member x (index, which starts at 0)
    ss[x] --> Self Switch 'X' (these are from the Yanfly plugin, not the normal Self Switches)
    sv[x] --> Self Variable 'X' (from the Yanfly plugin)


    Javascript reference:

    All valid Javascript is usable within the conditions. Some useful references:
    && --> AND
    || --> OR
    ! --> NOT

    === --> EQUAL TO
    !== --> NOT EQUAL TO
    > --> GREATER THAN
    >= --> GREATER THAN OR EQUAL TO
    < --> LESS THAN
    <= --> LESS THAN OR EQUAL TO

    + --> ADDITION
    - --> SUBTRACTION / NEGATIVE
    * --> MULTIPLICATION
    / --> DIVISION
    % --> MODULO
    ** --> EXPONENT


    Examples:

    To hide a choice if Switch # 4 is ON:
    ◆My Choice <<s[4]>>

    To disable a choice if Switch #4 is ON:
    ◆My Choice <<,s[4]>>

    To hide a choice if Switch # 6 is OFF:
    ◆My Choice <<!s[6]>>

    To hide a choice if Variable # 2 is greater than 10:
    ◆My Choice <<v[2] > 10>>

    To hide a choice if Variable # 3 is less than or equal to 10:
    ◆My Choice <<v[3] <= 10>>

    To hide a choice if Variable #1 is less than 10 and disable if Variable #1 is less than 20:
    ◆My Choice <<v[1] < 10, v[1] < 20>>

    To hide a choice if Switch #17 AND Switch #18 are ON:
    ◆My Choice <<s[17] && s[18]>>

    To disable a choice if Variable #17 equals 100 OR Variable #18 equals 100:
    ◆My Choice <<,v[17] === 100 || v[18] === 100>>

    To hide a choice if the Party leader's HP is less than 50:
    ◆My Choice <<p[0].hp < 50>>

    To disable a choice if the Actor #1's name is NOT Banjo:
    ◆My Choice <<,a[1].name() !== 'Banjo'>>

    To hide a choice if none in the party are named Kazooie:
    ◆My Choice <<p.every(member => member.name() !== 'Kazooie')>>

    To hide a choice if any in the party learned skill #4:
    ◆My Choice <<p.some(member => member.hasSkill(4))>>

    To disable a choice if every troop member's HP is below 25%:
    ◆My Choice <<,t.every(member => member.hp < member.mhp * .25)>>

    Compatibility:

    This plugin is compatible with the HIME Large Choices plugin.
    Make sure to install this plugin above HIME's plugin.

    This plugin is compatible with Yanfly's Self Variables and Self Switches plugin.
    Note the instructions in the help file for accessing these variables and switches. Plugin order doesn't matter for this one.

    Terms of Use:
    Free for use in commercial or non-commercial projects.
    Credits required to: Aloe Guvner

    Version History:
    • v1.2.0 (September 9 2018)
      • Update variable retrieval to use getters to avoid undefined values
    • v1.1.0 (August 23 2018)
      • Added capability to use Yanfly's Self Variables and Self Switches in conditions
    • v1.0.1 (July 1 2018)
      • Fixed bug with the width of the choice window
    • v1.0.0 (June 26 2018)
      • Initial release

    Download Link
    (Instructions: click the link, then right-click the "Raw" button and click "Save Link As...")
     
    Last edited: Oct 31, 2018
    #1
  2. Sauteed_Onion

    Sauteed_Onion Mmm Tasty Veteran

    Messages:
    554
    Likes Received:
    3,659
    Location:
    Perhaps on a steak or cheeseburger
    First Language:
    English
    Primarily Uses:
    RMMV
    #2
  3. Mystic_Enigma

    Mystic_Enigma The Doofiest of Dorks Veteran

    Messages:
    358
    Likes Received:
    1,270
    Location:
    In MY world, you are not welcome in my world!
    First Language:
    English
    Primarily Uses:
    RMMV
    This is something that has been on my mind for a while now. Thanks a bunch!
     
    #3
    Sauteed_Onion likes this.
  4. Kenode

    Kenode Veteran Veteran

    Messages:
    66
    Likes Received:
    24
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    I've been messing with it a little, and finally understood it's syntax. (I was a little confused at first, but turns out they're enabled by default, and will disable only if all options are true, so I had to reverse the options)

    Works great, but I have a question. Is it normal for it to extend the options menu width like this?
    [​IMG]

    Also, not sure if intentional, but it doesn't seem to hide an option if I am using the choices menu in a script. Not a big deal anyway, the main reason I was using scripted events before was to mess around with the hidden choices before this plugin, but I thought it would be worth mentioning.
     
    Last edited: Jun 28, 2018
    #4
  5. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,596
    Likes Received:
    1,003
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    @Kenode
    I need to check on the width issue, I think it must be calculating the width including the <<HIDE>>, but it needs to ignore that when calculating the width.
    I'll let you know when that part is fixed.

    For the other question, yeah, it only works from the event command "Show Choices", because I'm getting the choices directly from the event command and then processing it. I actually had to do it that way to be compatible with the HIME plugin (which is important for me).

    However, if you're constructing your choices all through scripts, then you don't even need this - just add the conditional logic into your script calls!
     
    #5
    Kenode and Sauteed_Onion like this.
  6. Kenode

    Kenode Veteran Veteran

    Messages:
    66
    Likes Received:
    24
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    That's actually the issue. I'm not sure how to do that effectively through conditionals. What I was trying was creating a list, and add to that list the options if certain condition is true, however I don't even know if I was doing that correctly. Still, this plugin is useful when in need to nest multiple functions, but I'd still like to know how to do it through script if I need to.
     
    #6
  7. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,596
    Likes Received:
    1,003
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    The bug with calculating the correct width of the window has been fixed, please download it again and try it!
     
    #7
    Sauteed_Onion and Kenode like this.
  8. Kenode

    Kenode Veteran Veteran

    Messages:
    66
    Likes Received:
    24
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    I've just tested it, I can confirm the bug has been fixed. Thanks!
     
    #8
    Sauteed_Onion and Aloe Guvner like this.
  9. Tea's Jams

    Tea's Jams I'm human Veteran

    Messages:
    764
    Likes Received:
    1,915
    First Language:
    English
    Primarily Uses:
    RMMV
    Very cool, thank you very much :)
     
    #9
  10. Amarok

    Amarok Veteran Veteran

    Messages:
    288
    Likes Received:
    710
    Location:
    Spain
    First Language:
    Spanish
    Primarily Uses:
    RMMV
    this is an amazing plugin, thank you! :D
     
    #10
  11. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,596
    Likes Received:
    1,003
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Update!

    You can now use Self Variables and Self Switches from Yanfly's Self Variables and Self Switches plugin in the conditions. This can cut down greatly on the complexity of large events. These can be access by using the following shortcuts in the condition.
    ss[x] --> Self Switch 'X' (from Yanfly's plugin, not the normal Self Switch)
    sv[x] --> Self Variable 'X' (from Yanfly's plugin)
     
    #11
  12. eXalted

    eXalted Villager Member

    Messages:
    29
    Likes Received:
    12
    First Language:
    English
    Primarily Uses:
    RMMV
    Thank you for the new update. Your plugin is awesome!
    Unfortunately, I'm receiving the following error when the Yanfly plugin is disabled:

    TypeError: Cannot read property 'ss' of undefined
    at Window_ChoiceList.markDisabledCommands (ALOE_ConditionalChoices.js:314)


    Maybe the two vars need to be in an Imported.YEP_SelfSwVar check?
     
    #12
  13. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,596
    Likes Received:
    1,003
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    You're right, that was a silly mistake! :confused:

    It's fixed now, and works with or without YEP_SelfSwVar. Also, I fixed it so the plugin order doesn't matter either.
     
    #13
  14. Frogboy

    Frogboy I'm not weak to fire Veteran

    Messages:
    1,672
    Likes Received:
    2,093
    Location:
    North Carolina, U.S.
    First Language:
    English
    Primarily Uses:
    RMMV
    This looks sweet. I'll definitely be using this it at some point. Awesome work!
     
    #14
  15. Summer夏

    Summer夏 Veteran Veteran

    Messages:
    31
    Likes Received:
    7
    First Language:
    中文
    Primarily Uses:
    RMMV
    This plugin is very useful,I found a small problem
    If the variable is initial(Variable #1=0),<<v[3] <= 10>>Will not take effect
     
    #15
    Aloe Guvner likes this.
  16. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,596
    Likes Received:
    1,003
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Great observation!

    In Javascript, if a variable is not declared, it gets an undefined value. Even though it shows "0" on the screen, it's actually undefined until a value is given to it. The issue is any condition such as `v[3] <= 10` is actually evaluated as `undefined <= 10` which will definitely not work as intended.

    I uploaded a new version (v1.2.0) that fixes this issue, please give it a try!
     
    #16
  17. Summer夏

    Summer夏 Veteran Veteran

    Messages:
    31
    Likes Received:
    7
    First Language:
    中文
    Primarily Uses:
    RMMV
    Thank you for your prompt reply, the problem has been fixed!
     
    #17
    Aloe Guvner likes this.
  18. Neo Soul Gamer

    Neo Soul Gamer Veteran Veteran

    Messages:
    612
    Likes Received:
    329
    Location:
    Nova Scotia, Canada
    First Language:
    English
    Primarily Uses:
    N/A
    Maybe it's just me, as I haven't tested it in a completely new project yet... But I'm getting quite the lag spike when loading the choice window while using this plugin. I'm going to run a few tests when I get home from work this evening. I just figured I'd mention it in case anyone ran into the same issue and knew the cause.

    EDIT: Disregard. Found the culprit after testing. This plugin works VERY well considering how much better it handles disabled/hidden choices compared to Yanfly's Extended Message Pack 1. Great job Aloe!
     
    Last edited: Oct 5, 2018
    #18
    Aloe Guvner likes this.
  19. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,596
    Likes Received:
    1,003
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    @Neo Soul Gamer Sorry, just saw this post.
    Was there a specific plugin that conflicted and caused the lag (just for curiosity)? I did a decent amount of testing using complex hide/disable conditions and never saw any lag, but of course, there's always a possibility of compatibility issues given the amount and variation of other people's plugins.
    Normally, I would try to pre-load the calculations for the hide/disable conditions to reduce potential lag, but given that you could change a variable immediately before a choice list, that wasn't possible.
     
    #19
  20. Neo Soul Gamer

    Neo Soul Gamer Veteran Veteran

    Messages:
    612
    Likes Received:
    329
    Location:
    Nova Scotia, Canada
    First Language:
    English
    Primarily Uses:
    N/A
    I'll be honest, I can't remember exactly what it was. LOL.

    However, I've heard about the bug before and it's totally unrelated. Your plugin wouldn't even be needed to reproduce the error.
     
    #20
    Aloe Guvner likes this.

Share This Page