Printing Characters Display Name in String?

Discuss authoring naninovel scenario scripts.
Post Reply
Dawnstar
Posts: 3
Joined: 14 Apr 2021 11:48

Printing Characters Display Name in String?

Post by Dawnstar »

I'm feeling quite stupid at the moment.

I've set up a few characters with a shorthand Name ID and then a more descriptive Display Name using the character options in the Config panel.

For Example character ID "A" then with a display name "Alice", and character ID MC (main character) would be inputted by the player using: @input MC summary:"Choose your name."

The label Name "A" works (shows the name) but when I try to use {A} in the text string it doesn't work.

MC: Home sweet home!
@char A
A: Why hello {MC}!
Player: Hi {A}, it's good to see you after so long... you're looking well!
A: You too {MC}

I guess I'm not declaring the variables correctly? or at all? I'm assuming this was done via the config panel?

Can anyone give me a example of how to set character display names up and use them in a string output?

For example in Renpy I would do something like:

define MC = Character("Joe")
define A = Character("Alice")

Then to output the variables in a string:

MC "Hello [A]! How are you doing?"
A "I'm fine [MC], thanks for asking."

I've looked through the docs but cannot see anything about using character names variable in a string?

Please someone put me out of my misery!

Cheers!

Dawnstar
Posts: 3
Joined: 14 Apr 2021 11:48

Re: Printing Characters Display Name in String?

Post by Dawnstar »

I've resolved this by setting a custom variable for each of the characters display names.

Seems a bit redundant though, as we already have a character object with a display name?

Oh well it works!

Elringus
admin
Posts: 521
Joined: 11 May 2020 18:03

Re: Printing Characters Display Name in String?

Post by Elringus »

The A part in A: Why hello {MC}! is a character ID, while MC is a custom variable you've assigned with the input command. That's why you can print the value of MC but can't do the same with A, as it 's not a variable.

It's possible to get display name via character ID in C#:

Code: Select all

static string GetName (string id) => Engine.GetService<ICharacterManager>().GetDisplayName(id);

It's also possible to expose this function to naninovel scripts (guide), so it can be used as follows:

Code: Select all

Player: Hi {GetName("A")}, it's good to see you after so long... you're looking well!

I've added this function in v1.16 (available in #download channel on the Discord), so it can be used out of the box.

Dawnstar
Posts: 3
Joined: 14 Apr 2021 11:48

Re: Printing Characters Display Name in String?

Post by Dawnstar »

That's great, thank you.

Post Reply