Status
Not open for further replies.

applechoirs

Warper
Member
Joined
Sep 11, 2015
Messages
3
Reaction score
2
First Language
Indonesian
Primarily Uses
RMMV
First is an apology if I'm not clear with my problem because English isn't my mother tongue.

So what am I trying to do here is to let players name their own character, but some names aren't allowed because they overlap with NPCs. Then, I want the name input prompt to be looped if players keep entering the same name/other names that aren't allowed.

So I did this:
loops.png
However, no matter what kind of name I input, I kept getting stuck in the loop. I searched and found that I should be putting the things that will break the loop in the If, not Else. If I want to follow that, that means the $gameActors script must be set to detect that the names inputted aren't forbidden names, and I don't know how to do it. In the first place, I'm not sure whether I did the $gameActors part right on the screenshot.

Any help with my problem? Thanks in advance.
 

autodidact

Veteran
Veteran
Joined
Nov 13, 2020
Messages
62
Reaction score
41
First Language
English
Primarily Uses
RMMV
Edit: Sorry, hasty reading. Ignore my post. See those posting below.

Well, it looks like your "if" check isn't actually checking the name that the player inputs.
Instead, it is checking the same $gameActors.actor(1).name every single time.

Try making it check for the variable that you are storing the name that the player inputs.
From your code, it looks like it should be $gameVariables.value(1)
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,880
Reaction score
8,587
First Language
German
Primarily Uses
RMMV
actually that part is correct @autodidact if you read what he wants to do.
The problem is because a comparison is always between two items, not one item and a list of items.

@applechoirs you'll have to rework the entire line, either checking for each name one after another or to check if the result is contained in the elements of an array (which is a different code, but I don't have that ready at the moment)
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
2,222
Reaction score
1,719
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi there!
Your script to check the value will not work like that, using a comma between each name. You have either do that:
JavaScript:
$gameActors.actor(1).name().toLowerCase() === "alex" || $gameActors.actor(1).name().toLowerCase() === "bob" || $gameActors.actor(1).name().toLowerCase() === "cherry" etc...

The "||" Operator means:
The actor name 1 is equal to alex OR Bob OR cherry...

If I was you, I will just create an array with every actor name on it and put that array into a variable(Before the loop). Put that script command on a script call:

JavaScript:
let usedNames = $gameParty.members().map(member => member.name().toLowerCase())
$gameVariables.setValue(ID, usedNames)

Then put this script on the conditional branch:

$gameVariables.value(ID).includes($gameActors.actor(1).name().toLowerCase())

"Includes" Is an array method to check if already exist an element in the array. In this case, we are checking if the actor name is on the array. If yes, this means that one party member already has this name.

Javascript Array
Javascript OR ||
 

Nolonar

Veteran
Veteran
Joined
Feb 18, 2018
Messages
271
Reaction score
374
First Language
French, German
Primarily Uses
RMMZ
Then put this script on the conditional branch:

$gameVariables.value(ID).includes($gameActors.actor(1).name().toLowerCase())

"Includes" Is an array method to check if already exist an element in the array. In this case, we are checking if the actor name is on the array. If yes, this means that one party member already has this name.

Just in case you (@applechoirs) don't want to compare the name with existing actor names (you did mention you wanted to avoid overlap with NPC names):

JavaScript:
["alex", "bob", "cherry"].includes($gameActors.actor(1).name().toLowerCase())
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
9,000
Reaction score
5,888
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Monday morning, and the sudden message: Hey, can you set up a full second lesson about pixel art till tomorrow?
No one:
Steam game achievement: "Die 100 times in easy mode".
I want to learn Javascript to create a custom menu, but I don't really know where to start.
One uncomfortable truth that has withstood the test of time, is how most people will stand by while they see a crime happening, unless it's illegal to stand by. We probably wouldn't have stories about "special heroes" or games about heroes if the "everyday common folk" were largely capable of being heroes. Heroes face dangers that most people are not willing to.
I'm having toooo much fun designing the new MP (Mental Psyche) system. I've only worked it out for enemies so far, but it's fun to stun them, then go after their MP and delete them instead to farm for better item drops.

Forum statistics

Threads
115,885
Messages
1,093,707
Members
151,128
Latest member
diskzaz
Top