Name Input Tutorial - Banning Certain Strings

Discussion in 'RPG Maker MV Tutorials' started by Archeia, Sep 26, 2017.

  1. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    13,768
    Likes Received:
    12,406
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    So your game allows the player to name their characters. But there's a catch, you don't want the player to name their main character with the same name as another character. Or worse, something unsavory. This tutorial is for cases like that.
    1. Create a text file of all the strings or phrases you want to ban from your game. For now I will go with "Ralph" and "Alex"
    2. Create a Common Event called "Name Input Processing"
    3. Create 2 Labels, One called START and One called VALID.
    Now under the label START, and assuming you can only name one character and we're going with Actor#1, put the Name Input Processing Command. Although this is optional and more about personal preference, I would put a Change Name command to set the name to blank. It should look something like this:
    Code:
    ◆Label:START
    ◆Change Name:PLAYER1,
    ◆Name Input Processing:PLAYER1, 7 characters
    ◆Label:VALID
    Insert a Conditional Branch with an else branch. Go to Page 4 and select Script. This is where we will insert the following code:
    Code:
    /BANNEDSTRING/i.exec($gameActors.actor(ID).name())
    So, since one of our banned strings is "Ralph", it should look like this:
    Code:
    /ralph/i.exec($gameActors.actor(1).name())
    And under the else command, just copy and paste this conditional branch and change "Ralph" to "Alex". You will end up something like this:

    Code:
    ◆Label:START
    ◆Change Name:PLAYER1,
    ◆Name Input Processing:PLAYER1, 7 characters
    ◆If:Script:/ralph/i.exec($gameActors.actor(1).name())
      ◆
    :Else
      ◆If:Script:/alex/i.exec($gameActors.actor(1).name())
        ◆
      :Else
        ◆
      :End
      ◆
    :End
    ◆Label:VALID
    As long as the strings "ralph" and "alex" are present, it doesn't matter what the case (upper or lower) of the name is, the system won't accept it.

    Now just above the Label: VALID, add a Show Message command that says something along the lines of "That name is already taken." and add a Jump to Label START. Then on the very last "else" of your conditional branch, add a Jump to Label VALID. By the end, your event command should look like this:

    Code:
    ◆Label:START
    ◆Change Name:PLAYER1,
    ◆Name Input Processing:PLAYER1, 7 characters
    ◆If:Script:/ralph/i.exec($gameActors.actor(1).name())
      ◆
    :Else
      ◆If:Script:/alex/i.exec($gameActors.actor(1).name())
        ◆
      :Else
        ◆Jump to Label:VALID
        ◆
      :End
      ◆
    :End
    ◆Text:None, Window, Bottom
    :    :That name is already taken.
    ◆Jump to Label:START
    ◆Label:VALID
    And that's about it! Now you just need to put it inside an event like this:
    Code:
    ◆Text:None, Window, Bottom
    :    :You want to name your character?
    ◆Common Event:Name Input Processing
    ◆Text:None, Window, Bottom
    :    :That's a really nice name \n[1]!
    Thank you @Shaz for helping me figure this out.
     
    #1
    adoren, Indsh, fizzly and 13 others like this.
  2. Touchfuzzy

    Touchfuzzy Rantagonist Staff Member Lead Eagle

    Messages:
    6,102
    Likes Received:
    4,785
    Location:
    Athens, GA, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    I once intentionally named every character in FFVII Sephiroth. It led to some very hard to follow conversations in game.
     
    #2
  3. Johan

    Johan Villager Member

    Messages:
    14
    Likes Received:
    1
    First Language:
    Swedish
    Primarily Uses:
    RMMV
    Nice guide:)
    Just a little tip when I did play around with script;

    You don't need to create a text file, did try this guide without it and it worked fine. Dunno why you have to create textfile :/

    /**
    * static
    * @method _getConstructorName
    * @param {Object} value
    * @return {String}
    * @private
    */
    JsonEx._getConstructorName = function(value) {
    var name = value.constructor.name;
    if (name === undefined) {
    var func = /^\s*function\s*([A-Za-z0-9_$]*)/;
    name = func.exec(value.constructor)[1];
    }
    return name;
    Right now I'm trying to figure how to insert ALL name in the same script to check if the name is inputted.
    Like banned name list + secret name list :)
    For now, I did create a common event like this guide, around 10 banned name, and another one for 5 secret name list :p
    This name script reminds me of Roller coaster Tycoon, where you can input "cheat" name on any guest to unlock something :)[/SPOILER]
     
    Last edited: Feb 28, 2018
    #3
  4. BishoujoHelper

    BishoujoHelper Veteran Veteran

    Messages:
    43
    Likes Received:
    33
    Location:
    California
    First Language:
    English
    Primarily Uses:
    RMMV
    @Johan It's true, you don't have to create such a text file. Perhaps @Archeia had a different implementation in mind originally.

    But the script construct provided above will start to grow ridiculously large as you add more banned names, and march toward the limit of nested If/Else/End blocks sanity. That's because it's been designed to add one level of nested If/Else for each name it checks, fall through to the unlabeled area with the "That name is already taken" message when a banned name matches, and have only one Jump at the very center of all the nested If/Else blocks.
    Here's a better way that does all the checking at one time, using the safer "test" functionality of regular expression evaluation just like "exec" does, and all you have to do different is type in all the banned names on one line in the editor, separated by "|" (vertical pipe) characters. The common event now looks like this:
    Code:
    ◆Comment:Refactor of a "Name Input with banned names list" post on
    :       :forums.rpgmaker.com by Archeia.
    ◆Label:LOOP_START
    ◆Change Name:PLAYER1,
    ◆Name Input Processing:PLAYER1, 7 characters
    ◆If:Script:/ralph|alex|Sephiroth|illegal/i.test($gameActors.actor(1).name())
      ◆Text:None, Window, Bottom
      :    :That name is not allowed.
      ◆Jump to Label:LOOP_START
      ◆
    :End
    ◆Label:VALID
    Note that "Sephiroth" is too big for 7 characters, but I couldn't resist. :wink:
    Also, just as in the original, "RALEX" or anything similar that embeds a banned name will be disallowed.
     
    #4
  5. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    13,768
    Likes Received:
    12,406
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    Hi! Thanks for all the alternate suggestions. I always appreciate more efficient ways to implement things. But, I have to make one thing clear about the text file.

    The reason for this is it's easier to see them all in a list and see if you missed any. Then start applying them in code. It's pure organizational purposes. It's a lot easier to read them in a text file than scrolling down the event editor. It's the same as making a flowchart of a code to see the logic faster vs. inputting random strings of code without thought and cause a lot of issues later.
     
    #5

Share This Page