Conditional "Show Choices" (hide or disable choices)

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Conditional "Show Choices"
by Aloe Guvner
Download Link
Note: This plugin is not under active maintenance.

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
 
Last edited:

Mystic_Enigma

A shadow keeping itself together...
Veteran
Joined
Mar 7, 2018
Messages
298
Reaction score
1,534
First Language
English
Primarily Uses
RMMV
This is something that has been on my mind for a while now. Thanks a bunch!
 

Kenode

Veteran
Veteran
Joined
Jun 17, 2018
Messages
68
Reaction score
26
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?


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:

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
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!
 

Kenode

Veteran
Veteran
Joined
Jun 17, 2018
Messages
68
Reaction score
26
First Language
Spanish
Primarily Uses
RMMV
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!
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.
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
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!
 

Tea's Jams

I'm human
Global Mod
Joined
Mar 28, 2017
Messages
1,039
Reaction score
2,576
First Language
English
Primarily Uses
RMMZ
Very cool, thank you very much :)
 

Amarok

Veteran
Veteran
Joined
Dec 15, 2016
Messages
294
Reaction score
723
First Language
Spanish
Primarily Uses
RMMV
this is an amazing plugin, thank you! :D
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
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)
 

eXalted

Veteran
Veteran
Joined
Oct 29, 2017
Messages
30
Reaction score
14
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)
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?
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
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.
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,702
Reaction score
2,205
First Language
English
Primarily Uses
RMMV
This looks sweet. I'll definitely be using this it at some point. Awesome work!
 

Summer夏

Veteran
Veteran
Joined
Jun 29, 2017
Messages
52
Reaction score
12
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
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
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!
 

Summer夏

Veteran
Veteran
Joined
Jun 29, 2017
Messages
52
Reaction score
12
First Language
中文
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!
Thank you for your prompt reply, the problem has been fixed!
 

Neo Soul Gamer

Veteran
Veteran
Joined
Aug 10, 2012
Messages
653
Reaction score
391
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:

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
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.
 

Neo Soul Gamer

Veteran
Veteran
Joined
Aug 10, 2012
Messages
653
Reaction score
391
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Posts

Latest Profile Posts

DoubleXP wrote on Tonbi's profile.
Hello Wondering if you take commissions?
I should make an itch.io page one of these days...Maybe for my next large update.
whoops, forgot to get started with Advent posts! coming shortly!

Another demo of the dynamic cloud cover system, this time complete with the original soundtrack composition (which sounds even goofier at this 2x playback speed). Much left to tweak but I like it so far.
And now, some custom emotions to give the character life... :kaoslp:

Forum statistics

Threads
105,778
Messages
1,016,346
Members
137,463
Latest member
Zyia
Top