Scripts for naming events

Hi there!

I'm in the process of creating game where the player can create villages, towns and cities on the world map. When the player creates these events, they have the opportunity to name them, or a random name can be chosen.

I've blocked off variables 101 to 500. These are to be used to store the names of the villages when they are created. I have another variable which is set to 100 when the game starts, and whenever a village is created, it has 1 added to it. This variable acts as a counter, and determines which variable in the 101-500 will be used to store the name of the village.

My hope is that players can use input name to name a dummy actor. This actor's name will then be stored in a variable. Which variable it is stored in should depend on the counter variable's current value. For example, the player names the first village by renaming the dummy actor, then the name of the dummy actor is stored in variable 101 because that's what the counter is on. the next village would be stored in 102, and so on and so forth. However, I can't seem to make my code work. Can any of you help me with that the javascript for such a setup should look like? I have some code below, but I get the feeling it is more simple than I've made it.


Here is what my scripting code looks like so far. I'm using YanFly's Self Variables.


◆Comment:This is set to 100 at the start of a new game
: :, and it represents the variables from 101 onward
: :that will store unique names. This will then be used in
: :the GabText messages.
◆Control Variables:#0041 Village Name Counter += 1
◆Comment:THIS WORKS NOW, ALTHOUGH SOME NAMES ARE NOT SPELLED CORRECTLY
◆Comment:=========================Change Name============================
◆Comment://get random value from array
◆Script:var items = ['This is filled with a bunch of text items but I'v hidden them for simplicity's sake'];
: :var item = items[Math.floor(Math.random() * items.length)];
: :// Make the self var 4 be the item from the list
: :$gameVariables.setValue(4, item);
: :// Make self variable 42 be equal to the counter
: :$gameVariables.setValue($gameVariables.value(42), $gameVariables.value(41));
: :// Make variable (whatever the counter is currently at) equal to the item from the list
: :$gameVariables.setValue($gameVariables.value($gameVariables.value(41)), item);
◆Control Variables:#0042 Self Var NameNumber = Village Name Counter
◆Script:// Make variable (whatever the counter is currently at) equal to the item from the list (or self var 4)
: :$gameVariables.setValue($gameVariables.value($gameVariables.value(41)), $gameVariables.value(4));
◆Comment:$gameActors.actor(actorId).setName(n)
◆Comment:"If you want to change an Actor's name based on another Actor's name:
: :$gameActors.actor(actorId).setName($gameActors.actor(actorId).name())"
◆Comment:◆Script:$gameActors.actor(23).setName($gameVariables.value(4))
I'm bad at JS, so rather than give you the wrong answer, I'll suggest an alternative:

if you make some dummy actors, you can cut the variables and just use name input to save the names to each of those. It's sort of a work-around, but I honestly think that's the easiest route unless I'm missing some functionality you need.
I'm bad at JS, so rather than give you the wrong answer, I'll suggest an alternative:

if you make some dummy actors, you can cut the variables and just use name input to save the names to each of those. It's sort of a work-around, but I honestly think that's the easiest route unless I'm missing some functionality you need.
You know, I didn't explain myself well, but you actually did help me fix the issue. I'm still using scripting and variables, but I'm also using actors for the names, and I've fixed the issue. I will attach a photo of what I did in the morning.

Thank you for your help!

Original thread: https://forums.rpgmakerweb.com/threads/scripts-for-naming-events.148386/