Script for add/remove characters from name

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
Hello,

Is there a way to edit the character name through script? I'd like to recreate and old name changer from my game made with RM2K3 and I want to avoid heavy scripting/plugins.

I found that this script can change the name of the character #1 with the variable #4 value:

$gameActors.actor(1).setName($gameVariables.value(4));

But what if I wanted to remove the last character or ad a letter? I'm new to javascript and RMV , I tried many options but I have to figure out how RMV works to do that.

Any help? :)
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
string.length = string.length -1 should work for subtracting. At least this worked in python.
If this doesn't work, then perhaps string -= string[-1].

Adding letters is same as everywere, string += letter you wanna add.

This isn't totally about figuring out how RMMV works though, but really basic javascript :D
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
Thank you!

So the script would be something like this...?

$gameActors.actor(1).setName($gameVariables.string -= string[-1]);

I'm getting started with java so I don't have the right syntax figured out yet ^^

Anyway, whatever I try it says "string is not defined" :(
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
$gameActors.actor(1).setName($gameVariables.value(4) - $gameVariables.value(4)[-1])
in this particular case. Also, javascript, not java :)
Before you work on javascript, I suggest you learn it first a bit, it will be much easier.
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
Ah sorry! I copied the wrong code!
The $gameVariables.value(4) was just a placeholder for the code, its not useful for my purpose.

what I'm trying is something like:

$gameActors.actor(1).setName($gameActors.actor(1) -= string[-1]);

But I get error, I also noted that there is no string command in your code.

I've made up my mind to learn javascript, but I wanted to try some small thing right on the battlefield first :)
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
In this case $gameActors.actor(1).setName($gameActors.actor(1) - $gameActors.actor(1)[-1]) should do the trick.
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
That string change the name to Not a Number (NaN).
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
I'm an idiot :D Forgot completely to type in name.
$gameActors.actor(1).setName($gameActors.actor(1)._name - $gameActors.actor(1)._name[-1])
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
That's strange because I keep getting NaN :/
Can you confirm?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
Ok, this time it will work!
The reason is, for some unknown reason javascript doesn't recognize [-1] as last and throws in undefined.
So now it will work.
$gameActors.actor(1).setName($gameActors.actor(1)._name - $gameActors.actor(1)._name[$gameActors.actor(1)._name.length -1])
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
Believe it or not, still getting NaN :frown:
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
Are you kidding me :D
I know you aren't.

Alright, time for brute force.
$gameActors.actor(1).setName($gameActors.actor(1)._name.slice (0, $gameActors.actor(1)._namelength - 2))
If this doesn't work, I don't know what will.
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
Well, it doesn't give NaN anymore, but the hero name (wich is 4 letters btw) disappear completely.
Didn't immagined It could be so tricky @_@
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
Ok, then one question. What kind of a name are you using?
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
Character 0001 is named "Rain"
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
Jesus... I missed one dot and missed missing that dot!

$gameActors.actor(1).setName($gameActors.actor(1)._name.slice (0, $gameActors.actor(1)._name.length - 2))

Now the dot is there. Really sorry for that. It's these small mistakes that turn a 5 min job into 5 hour one though, I can guarantee that :D
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
It works!! :D
By this logic, wat's the script for adding a letter?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
Adding letters uses normal addition.
 

Artemis

Villager
Member
Joined
Dec 9, 2015
Messages
22
Reaction score
3
First Language
Italian
Primarily Uses
RM2k3
I've made it!

it is $gameActors.actor(1)._name += "abc";

For further reference :)

Thank you!
 

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

Latest Threads

Latest Profile Posts

What worst could happen when your driver said "I know a shortcut"?
Creating Telekinesis script for another user, couldn't resist doing a scripted scene to display progress, when I could have just shown it in seconds XD
My city has enacted some measures to lock down the city from the plague for the first time in China and it has been reported even on some international news. :kaomad2: I'd never imagined my little city would be paid attention to in such a way.
I made a lot of progress on the 2nd stage of my game. Only 10 levels but it took over a week to design and implement. Cant wait to share more info.

Forum statistics

Threads
93,628
Messages
914,087
Members
123,202
Latest member
Legend20
Top