Parameter for Tracking 'i' variable

Discussion in 'Learning Javascript' started by 22pepperjack, Jun 11, 2018.

Thread Status:
Not open for further replies.
  1. 22pepperjack

    22pepperjack Veteran Veteran

    Messages:
    236
    Likes Received:
    72
    Location:
    Northwest Arkansas
    First Language:
    English
    so im editing the JS for a Yanfly script, and within it is the following line:

    for (var i = 1; i <= 10; i++) {

    this line is being used to create a dynamic list of variables to display. allowing for the list to be however big or small the user wants, however, im trying to create a Parameter that counts how many variables are currently being displayed since the number changes throughout the game. is there a line i can insert after this one that basically says "if 'i' is increased by 1, then increase this parameter by 1'? the idea being that by the end of the dynamic lists creation the parameter will be equal to the variable.

    im not really asking for help with the script, just this algorithm, so i beleive this to be the right forum, if not, thank you moderator for moving it over! also, if context is needed for the algorithm, its in Yanfly's MainMenuVariable script. line 329
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    28,002
    Likes Received:
    6,327
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    I think you've mistaken something here.
    that i is the control variable of a for-loop, which means it is always counted from 1 to 10 (in this case, starting from var i=1 and counting i++ as long as i<=10), it never goes higher than 10 and always goes up to 10 before the loop is completed.

    It would help if you give a link to the specific script that you're talking about and what the for-loop does in that script.
     
    #2
  3. 22pepperjack

    22pepperjack Veteran Veteran

    Messages:
    236
    Likes Received:
    72
    Location:
    Northwest Arkansas
    First Language:
    English
    Oh, I thought I had it figured out lol guess not, I’m at work now but will provide a link and description when I get home later, thanks for clarifying my mistake though!
     
    #3
  4. 22pepperjack

    22pepperjack Veteran Veteran

    Messages:
    236
    Likes Received:
    72
    Location:
    Northwest Arkansas
    First Language:
    English
    alright, update time!

    this is the link to the Yanfly script:
    http://yanfly.moe/2017/07/07/yep-145-main-menu-variable-window-rpg-maker-mv/

    in this script the built in adjustable parameters includes slots for up to 10 variables; making it so that at your whim you can say "hey when this switch is on, display this variable on the main menu". i'm only using 6 of the built in parameters instead of the available 10, but i need a parameter to keep track of how many variables are currently being displayed.

    i see now how that "i" is being used, but im still having trouble adjusting the code to add in an extra parameter that counts how many variables are active at one time. or in this case, im looking for a way to make a parameter that says "hey, how many times is "i" being used to draw a variable?" instead of "how many variables are linked to it."

    not sure if im searching in the wrong area for a solution to this, but all help is appreciated!
     
    #4
  5. Aloe Guvner

    Aloe Guvner Walrus Veteran

    Messages:
    1,454
    Likes Received:
    930
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    You weren't quite in the right place, it's down at line 371. Here's an example to get you started, I put comments on the lines that I added.

    Code:
    Window_MainMenuVariable.prototype.refresh = function() {
      var myCounter = 0; //added
      this.contents.clear();
      var x = this.textPadding();
      var y = 0;
      for (var i = 1; i <= this.maxVariables(); i++) {
        if (this.showVariableData(i)) {
          this.resetFontSettings();
          y = this.drawVariableData(i, x, y);
          myCounter += 1; //added
        }
      }
      var width = this.contents.width - this.textPadding() * 2; //added
      this.drawText(myCounter, x, y, width, 'right'); //added
    };
    
     
    #5
  6. 22pepperjack

    22pepperjack Veteran Veteran

    Messages:
    236
    Likes Received:
    72
    Location:
    Northwest Arkansas
    First Language:
    English
    ok, so that part is working perfectly to display the number, thanks for the help Aloe Guvner! however, the last issue im having is in my attempt to link it back to a Parameter that i can call from an eval later on. i tried placing
    "Param.MMVarCounter = mycounter;" both early on in the parameters section of the script and right before and after the above lines, i also tried a variation with "Param.MMVarCounter = var mycounter;" in the same places, but both are coming back as basically non-existant or errors as it seems to just void out and not run the script at all. didnt think parameters and variable were this hard to grasp lol, although i know what a loop function looks like in JS, had no idea thats what i was looking at before XD im more used to GML instead.

    EDIT:
    Nevermind i got it working, i placed the "Param.MMVarCounter" parameter up above in teh parameters section and had it equal zero, then right above the var width line down below, had it equal myCounter. thanks again guys!
     
    Last edited: Jun 12, 2018
    #6
  7. mlogan

    mlogan Global Moderators Global Mod

    Messages:
    13,607
    Likes Received:
    7,520
    Location:
    Texas
    First Language:
    English
    Primarily Uses:
    RMMV

    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.

     
    #7
Thread Status:
Not open for further replies.

Share This Page