Name Input Tutorial - Banning Certain Strings

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
14,890
Reaction score
15,056
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.
 

Johan

Villager
Member
Joined
Feb 23, 2017
Messages
14
Reaction score
2
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:

BishoujoHelper

Veteran
Veteran
Joined
May 6, 2017
Messages
54
Reaction score
45
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.
 

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
14,890
Reaction score
15,056
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.

Create a text file of all the strings or phrases you want to ban from your game.
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.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

The more I look at the QPlugins... The more I am amazed at what they can do. Which I'm not going to lie is pretty awkward, because I already consider them far and away the best plugins MV has to offer. :kaoback:
spending a week trying to figure out what was wrong with my font has me DED
504 threads to go upon the time of this post until the forum reaches 100k threads. Thread Dead Redemption. Thready Van Halen. Thread Zeppelin. Doesn't have to be a band or a game
Random thought: Looks like putting in effort in learning a language is like a taboo for most people. :kaoswt2:
Not sure about RPG Maker MZ ; We see a lot of things, but they could have enhanced a lot of things in MV first... We're at the era of updates nowadays, not new products over and over and over :/

Forum statistics

Threads
99,500
Messages
966,116
Members
131,130
Latest member
Player-Unknown
Top