Help with using Actor's first letter of his/her's name with Variable

Hello, all! Jack here.

I know there are script calls for things like this to capitalize Actor's names:


var charName = $gameActors.actor(ActorID).name().toUpperCase();
$gameVariables.setValue(VarID, charName );

But is there a way to use only the first letter of the Player's chosen name? Would like to have this to help with creating a sad scene or a surprise scene. Whatever scenes there are. Lol.

Any help would be appreciative.



EDIT!

This post has been solved thanks to @Eliaquim and @Warilized !

Here is the example.

@Eliaquim Script Call

Change ActorID to the number of Actor of your choosing. Replace INDEX with 0. And then replace VarID with the Variable you wish to use in the game.

var firstLetter = $gameActors.actor(ActorID).name()[INDEX]
$gameVariables.setValue(VarID, firstLetter );

Should show like this;

var firstLetter = $gameActors.actor(1).name()[0]
$gameVariables.setValue(1, firstLetter );


@Warilized Script Call

It is pretty much the same as the one above.

var charName = $gameActors.actor(ActorID).name();
var capitaliseName = charName.charAt(0).toUpperCase() + charName.slice(1);
$gameVariables.setValue(VarID, charName );

This is Warilized's words.

.charAt(0) will give you the first letter of their name (e.g. "W")
.slice(1) will give you their name starting at second letter (e.g. "arilized")
Hi!

To get only the first letter of any string, in your case, the actor name, you can use this:

var firstLetter = $gameActors.actor(ActorID).name()[INDEX]
replace INDEX with 0.

But if you want to capitalize only the first letter of the actor name, then you do this:

JavaScript:
var name = $gameActors.actor(ActorID).name()
var firstLetterUpperCase = name[0].toUpperCase()
var actorName = firstLetterUpperCase + name.substr(1)

actorName will return the Actor's name with the first letter capitalized.

For reference: substr method
You could use

Code:
var charName = $gameActors.actor(ActorID).name();
var capitaliseName = charName.charAt(0).toUpperCase() + charName.slice(1);

.charAt(0) will give you the first letter of their name (e.g. "W")
.slice(1) will give you their name starting at second letter (e.g. "arilized")
1630238978238.png


As I wrote in my game. Lol. You guys really are beautifully awesome! 😀 I didn't want to sound all dramatic but this is actually a dream come true for me. Thank you so much.

If curious, actually using both of yours.

@Eliaquim That String Prototype is actually pretty handy. Though, still trying to study the basic OOP. Lol. So I bookmarked it. Your help is not wasted. Thank you. 🙂

@Warilized This actually pretty much solves everything. Took me a bit, too. But I figured it out, as well. Thank you so much for your help. It really is highly appreciative. 😀 ps... I like your picture. As an Artist, I still have a lot to learn. 😀

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.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-using-actors-first-letter-of-his-hers-name-with-variable.139977/