MV - YEP Option Core: How to add a new option to the menu that controls a switch &/or variable?

● ARCHIVED · READ-ONLY
Started by TheAM-Dol 9 posts View original ↗
  1. I have decided to repurpose my thread on this problem in hopes that the SEO will have it turn up in google searches more easily. Hopefully those who hit the same brick wall as myself will find this thread and utilize it to overcome that hurdle without having to spend money to fix it (like I wound up having to do). If you want to know more about my original problem, I stuffed my original post into a spoiler tag at the bottom of this post.

    So, in the end, I decided to commission someone to help me do this since I didn't get any answers here, nor could I find any answers about this through googling.
    I'm posting what I commissioned here because I am hoping that anyone who is also looking for this answer will now stumble across what I paid money for:

    Requirements:
    Before showing the code, it's important to note that without the access to global switches and variables, this won't work. In order to use global variables and switches, you will need Olivia's meta controls which you can find here:
    Olivia's Meta Controls
    And obviously, all of this require's YEP Option Core:
    YEP Option Core

    The Code:
    This is the code for for menu options that utilize switches:
    Spoiler
    In my game, I created a video effect filter to add a little spice to my game. This option in my option menu gives the player the option to turn the filter off in the game if they find the effect too distracting or just prefer a cleaner looking image overall. Both the enabling of this filter (seen here) and the intensity of the filter (seen below in the variable option menu) are controlled through a parallel common event.

    I'm pasting all the code for the entire thing, even if most of it is default code that doesn't need to be changed. This is to help those who are dumb with coding (like myself) hopefully feel more confident that this is the correct answer.

    "Make Option Code"
    Code:
    this.addCommand(name, symbol, enabled, ext);

    "Draw Option Code"
    Code:
    var rect = this.itemRectForText(index);
    var statusWidth = this.statusWidth();
    var titleWidth = rect.width - statusWidth;
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.drawOptionsName(index);
    this.drawOptionsOnOff(index);

    "Process OK Code"
    Code:
    const index = this.index();
    symbol = this.commandSymbol(index);
    const value = this.getConfigValue(symbol);
    this.changeValue(symbol, !value);
    
    const catalyst = $gameSwitches.value(38);
    if (catalyst) {
      $gameSwitches.setValue(38, false);
    } else {
      $gameSwitches.setValue(38, true);
    }
    Please note the number 38 in this code. The number 38 is associated with my game's switch ID number. This number needs to be changed for your game!

    "Cursor Right Code"
    Code:
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    this.changeValue(symbol, true);
    $gameSwitches.setValue(38, true);
    Same note as above: change the number 38 to match the switch ID number of your game.

    "Cursor Left Code"
    Code:
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    this.changeValue(symbol, false);
    $gameSwitches.setValue(38, false);
    Same note as above: change the number 38 to match the switch ID number of your game.

    "Default Config Code"
    Code:
    ConfigManager[symbol] = false;

    "Save Config Code"
    Code:
    config[symbol] = ConfigManager[symbol];

    "Load Config Code" (If you wish to set the default value to "TRUE" (on) instead of "FALSE" (off), do not use this code. Please read the "Default value" section below.
    Code:
    ConfigManager[symbol] = !!config[symbol];

    Setting Default Values
    For setting the "Default" value to "TRUE", there seems to be a poor interaction between YEP Option Core and rpg_managers which disables the ability to assign a default value. This discovery is thanks Palin via this thread linked. (the thread will also be linked in the troubleshooting section of this post).
    Set the "Default Config Code" to "true"
    Code:
    ConfigManager[symbol] = true;
    then change the "Load Config Code" to this:
    Code:
    var value = config[name];
    if (value !== undefined) {
       ConfigManager[name] = value;
    } else {
       ConfigManager[name] = true;
    }

    I have not tested this with variables, thus it has been hidden in the "switch" spoiler tag.

    This is the code for menu options that utilize variables:
    Spoiler
    In my game, I created a video effect filter to add a little spice to my game. This option in my option menu gives the player the option to change the "intensity" of the filter effect in the event the player likes the effect, but finds it default setting either too weak to enjoy or too intense to use. Both the enabling of this filter (seen above in the switch menu option) and the intensity of the filter (seen here) are controlled through a parallel common event.

    I'm pasting all the code for the entire thing, even if most of it is default code that doesn't need to be changed. This is to help those who are dumb with coding (like myself) hopefully feel more confident that this is the correct answer.

    "Make Option Code"
    Code:
    this.addCommand(name, symbol, enabled, ext);

    "Draw Option Code"
    Code:
    var rect = this.itemRectForText(index);
    var statusWidth = this.statusWidth();
    var titleWidth = rect.width - statusWidth;
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.drawOptionsName(index);
    var value = this.getConfigValue(symbol);
    var rate = ((value) / 3).clamp(0, 1);
    if (value > 6) {
      var gaugeColor1 = this.textColor(15);
      var gaugeColor2 = this.textColor(0);
    } else {
      var gaugeColor1 = this.textColor(15);
      var gaugeColor2 = this.textColor(0);
    }
    this.drawOptionsGauge(index, rate, gaugeColor1, gaugeColor2);
    this.drawText(" ", titleWidth, rect.y, statusWidth, 'center');
    the numbers you see next to "this.textColor" are the numbers pulled from your img/system image file. If you want to change the look of the gradient on the option bar, change these numbers.

    "Process OK Code"
    Code:
    const index = this.index();
    symbol = this.commandSymbol(index);
    let value = this.getConfigValue(symbol);
    value += 1;
    if (value > 3) {
      value = 0;
    }
    value = value.clamp(1, 3);
    $gameVariables.setValue(40, value);
    this.changeValue(symbol, value);
    There are 2 things you need to adjust here for your game.
    1) Please note the line "$gameVariables.setValue(40,value);" The number 40 is the variable ID number I am controlling in my game. You will need to change this number to match your game.
    2) The number of "ticks" this bar can do is controlled here. The "if (value > 3)" line is part of the maximum value the bar can show. Below that, you find this line: "value = value.clamp(1, 3);" clamp is the limiter here. 1 is going to be the lowest possible value, and 3 is going to be the highest possible value. Change this according to your game. (Can't confirm since I am a dummy, but you may need to adjust the clamp value in the "Draw Option Code" as well)

    "Cursor Right Code"
    Code:
    const index = this.index();
    symbol = this.commandSymbol(index);
    let value = this.getConfigValue(symbol);
    value += 1;
    value = value.clamp(1, 3);
    $gameVariables.setValue(40, value);
    this.changeValue(symbol, value);
    Once again, you will need to change: 1) the number 40 to match your game's variable ID number. 2) the clamp values.

    "Cursor Left Code"
    Code:
    const index = this.index();
    symbol = this.commandSymbol(index);
    let value = this.getConfigValue(symbol);
    value -= 1;
    value = value.clamp(1, 3);
    $gameVariables.setValue(40, value);
    this.changeValue(symbol, value);
    Once again, you will need to change: 1) the number 40 to match your game's variable ID number. 2) the clamp values.

    "Default Config Code"
    Code:
    ConfigManager[symbol] = 0;

    "Save Config Code"
    Code:
    config[symbol] = ConfigManager[symbol];

    "Load Config Code"
    Code:
    var value = config[symbol];
    if (value !== undefined) {
      ConfigManager[symbol] = Number(value).clamp(1, 3);
    } else {
      ConfigManager[symbol] = 1;
    }
    Once again, make sure to change the clamp values here.

    In addition to the filter that I wanted to integrate into my option menu, I also wanted to integrate a "Full screen" option to the menu. Yes, we all know you can press f4 to go full screen, but I wanted to make my game as close to professional as I can reasonably afford, so providing a clear option in the menu is a step closer towards that.

    Spoiler
    Originally, I had been using SRD Fullscreen option as a plugin to add the option to the vanilla option menu, however, YEP's OptionCore overrides the default option menu and therefore overrode SRD Fullscreen.
    So, Synrec helped me build a brand new full screen option into the game using YEP's OptionCore. This full screen option does not require the SRD plugin.

    "Make Option Code"
    Code:
    this.addCommand(name, symbol, enabled, ext);

    "Draw Option Code"
    Code:
    var rect = this.itemRectForText(index);
    var statusWidth = this.statusWidth();
    var titleWidth = rect.width - statusWidth;
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.drawOptionsName(index);
    this.drawOptionsOnOff(index);

    "Process OK Code"
    Code:
    const index = this.index();
    symbol = this.commandSymbol(index);
    const value = this.getConfigValue(symbol);
    this.changeValue(symbol, !value);
    if(!value){
      Graphics._requestFullScreen();
    }else if(value){
      Graphics._cancelFullScreen();
    }

    "Cursor Right Code"
    Code:
    const index = this.index();
    symbol = this.commandSymbol(index);
    const value = this.getConfigValue(symbol);
    this.changeValue(symbol, true);
    Graphics._requestFullScreen();

    "Cursor Left Code"
    Code:
    const index = this.index();
    symbol = this.commandSymbol(index);
    const value = this.getConfigValue(symbol);
    this.changeValue(symbol, false);
    Graphics._cancelFullScreen();

    "Default Config Code"
    Code:
    ConfigManager[symbol] = false;
    if(ConfigManager[symbol]){
      Graphics._requestFullScreen();
    }else if(!ConfigManager[symbol]){
      Graphics._cancelFullScreen();
    }

    "Save Config Code"
    Code:
    config[symbol] = ConfigManager[symbol];

    "Load Config Code"
    Code:
    ConfigManager[symbol] = !!config[symbol];
    if(ConfigManager[symbol]){
      Graphics._requestFullScreen();
    }else if(!ConfigManager[symbol]){
      Graphics._cancelFullScreen();
    }

    Credit:
    All of the code above was written by Synrec, I just paid him to make it. It would be nice to receive credit (both Synrec and myself - please credit me as "Nolan Alighieri" and not my username) if you use it, but it's not necessary.

    Troubleshooting:
    If you are still struggling with this, unfortunately I likely won't be able to troubleshoot any problems. As I mentioned, I'm a coding dummy. However, there have been some links posted in this thread that may help you as well. Rather than have you scroll through this entire thread looking for them, allow me to summarize:
    This video is a tutorial on how to set up a switch in YEP Options core.


    I had originally used this video to set up the switch, and it works fine, however the video doesn't really explain a lot about what it is you are writing, so it's not useful for learning, only useful for imitating.

    And some of the code shared in the two threads below may be helpful to some (I had used some of it originally before ultimately deciding to scrap it all and just go to Synrec)
    This thread
    and
    this thread

    Additionally, this thread linked, was used to set default values for menu options that control switches.

    If you are still struggling to get whatever it is you are trying to get working, I would recommend starting a new thread, rather than posting here. Sharing this thread may help others know what you are working from.

    Here is the end result:
    Options.PNG

    Original Post
    Hi,
    I created a visual filter for my game, but I can easily imagine some folks might not enjoy it, so I wanted to allow people to either turn it on or off.

    I thought YEP Option core would do the trick, but I don't know what I am doing with it :LZSlol: (but I do like the make over the option menu got!)
    So here's how I would like to break it down:
    1 option is to simply toggle the effect on or off. So in the option menu this would just turn a switch on or off.
    The second option would control the intensity of the effect through a variable. Where setting the variable to 1 is a lower intensity, 2 is moderate, and 3 is the full effect. (Would be great if I could rename these values too to something like "low, medium, high" :LZSwink:)

    Thank you for your help:LZSproud:

    edit 08/03/2022
    Added troubleshooting to set default values for menu options that utilize switches.
  2. I'm not an expert in YEP Collection, but as I remember, you always provide JS codes to do something, am I right?

    To turn on/off a switch, you need this command:
    Code:
    $gameSwitches.setValue(1, true)
    or
    Code:
    $gameVariables.setValue(1, false)
    Replace 1 with your Switch Id.

    Variables:
    Code:
    $gameVariables.setValue(1, 42)
    to assign the value 42 to Variable 1.
  3. follow this [tutorial], it was somewhere on this forum too, I would
    also recommend [Olvia_MetaControls].

    if more players choose it, it might be trouble some, but it works
    for players on their own pc :)
  4. ShadowDragon said:
    follow this [tutorial], it was somewhere on this forum too, I would
    also recommend [Olvia_MetaControls].
    Great links! Thank so much. I was able to successfully add the toggle switch for the noise filter, but he didn't cover adding variables in the tutorial. Some of @Aerosys code helps, but I'm a bit lost on setting up the variable to control intensity.

    edit:
    I should mention, I'm pretty dense when it comes to programming, I'm pretty helpless at this kind of stuff.

    Second edit:
    Well, I got the menu item for toggle switch to show up, but actually turning the switch on/off in the option menu doesn't seem to be affecting the filter itself. (sort of, read edit number 3)Here are some screen shots:

    My set up in Options Core:
    Spoiler
    Options.png

    CursorRightOptions.PNG

    CursorLeftOptions.PNG

    The common event that controls the noise filter:
    Spoiler
    I thought having the trigger set to parallel with the switch would mean the common event should only run when the switch is active, but for debugging purposes, I tried manually forcing it to disable by adding a conditional branch (it may still be necessary to make sure to erase the filter)
    NoiseFilterEvent.PNG

    Edit 3:
    More debugging on this.
    So I noticed pressing the okay key on the option menu seems to work...some times?
    (It only works "sometimes" because the logic gets messed up if I push the left/right keys)
    But using the left/right keys does nothing when controlling the options menu.
  5. toggle switch is mostly the same way adding variables :)
    it might be slightly difference depending what you need.

    if you want to use numbers, than you can add numbers,
    but it should be evented inside the game or parallel if needed
    to say what each value does :)
  6. ShadowDragon said:
    toggle switch is mostly the same way adding variables :)
    it might be slightly difference depending what you need.

    if you want to use numbers, than you can add numbers,
    but it should be evented inside the game or parallel if needed
    to say what each value does :)
    I'm sorry, your information is not clear.
    I have been playing around with the code some more, trying to look at how other options already defined by default are handled by the plugin...but I don't feel like I am any closer to figuring this out.

    Here's my non-working attempt to use variables; part of this code is copied from the battle speed option, and then at the top I attempted to replicate the information from the tutorial, but failed to grasp how or where to assign the default value for the variable. Nor do I really understand how to control the variables.
    intensity1.PNG

    And here it is in game. I copied code from the window R/G/B/ draw code and got it to render a bar to represent how "intense" the effect will be. Unfortunately the bar doesn't move at all, and it shows the 255 value (since it was copied from the RGB option) instead of changing to 3.
    Intensity2.PNG
  7. I didn't play with variables, if there is an option for RBG colors, it can be
    copy paste and change inside.

    I dont know JS logic behind or how it's done, so I cannot help you there.
    but there is a way to set numbers (1, 2, 3 ,4 ,5 ,6) and each number has
    it's own value what will be running.

    as I learn JS, I just give you a direction for game variables, not how to
    set it up which I dont know in the plugin, but there are people with more
    knowledge or knowledge how YEP_OptionCore works to help you out
    with some coding.

    if you are in the lunatic discord server, you might try your luck there.
  8. Thanks for your help anyways.
    I trying finding the lunatic discord server, but wasn't able to.
    I've just been google searching this - there's no way I am the only person with this problem. A few threads have come up, though they are looking for help integrating other plugin's option menus into YEP_OptionCore, but the concept is similar.
    I've at least managed to make the bar react appropriately with 3 steps for low, medium, and high.

    The problem I am still having is passing the variable (NoiseFilterIntensity) into this bar. As things are right now, the bar controls nothing, it just looks pretty.
    I got the relevant information from this thread and this thread and here is the code so far:
    Draw code:
    Code:
    var rect = this.itemRectForText(index);
    var statusWidth = this.statusWidth();
    var titleWidth = rect.width - statusWidth;
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.drawOptionsName(index);
    var value = this.getConfigValue(symbol);
    var rate = ((value) / 3).clamp(0, 1);
    if (value > 6) {
      var gaugeColor1 = this.textColor(15);
      var gaugeColor2 = this.textColor(0);
    } else {
      var gaugeColor1 = this.textColor(15);
      var gaugeColor2 = this.textColor(0);
    }
    this.drawOptionsGauge(index, rate, gaugeColor1, gaugeColor2);
    this.drawText(" ", titleWidth, rect.y, statusWidth, 'center');

    OK CODE
    Code:
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    value += 1;
    if (value > 3) {
      value = 0;
    }
    value = value.clamp(0, 3);
    this.changeValue(symbol, value);

    CURSOR RIGHT
    Code:
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    value += 1;
    value = value.clamp(1, 3);
    this.changeValue(symbol, value);

    CURSOR LEFT
    Code:
    var index = this.index();
    var symbol = this.commandSymbol(index);
    var value = this.getConfigValue(symbol);
    value -= 1;
    value = value.clamp(1, 3);
    this.changeValue(symbol, value);

    In addition, I am still struggling to get the CURSOR RIGHT and CURSOR LEFT code to work properly for the Noise Filter toggle switch. Right now, only the OK code works

    edit:
    small one, a bonus for anyone able to help me out:
    turns out Option Core has disabled SRD_FullscreenOption. Looks like I need to integrate it in a similar way to one of the threads I linked above, but I'm absolutely tapped out on figuring this stuff out for now...
  9. Hey thanks, Nolan! Now I don't need to trial and error to recreate the gameplay options I had in VX Ace. This was a big help. :LZSwink: