Yarn2: Override actor's name?

Announcements, support questions, and discussion for the Dialogue System.
kko828
Posts: 17
Joined: Sun Nov 05, 2023 1:59 am

Yarn2: Override actor's name?

Post by kko828 »

Hi, I'm using the dialogue system toghether with Yarn2 and wanna override actor's name on some lines.

When I was using Yarn2 alone, I added a tag as shown below, parsed the tag on the C# script, and temporarily overridden the actor's name.

In .yarn file:

Code: Select all

Dude: I'm misterious guy. #display_as:???
In C#(It overrides Yarn's BaseClass):

Code: Select all

public class CharacterNameView : DialogueViewBase
    {

        [SerializeField]
        private TextMeshProUGUI text = null!;

        public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
        {
            var displayAs = dialogueLine.GetTag("display_as");
            if (displayAs != null)
            {
                text.text = displayAs;
            }
            else if (dialogueLine.CharacterName == null)
            {
                Hide();
            }
            else
            {
                Display(dialogueLine.CharacterName);
            }
            onDialogueLineFinished();
        }
        }
        
Is it possible to do something like this with your system?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Yarn2: Override actor's name?

Post by Tony Li »

Hi,

I recommend using the ChangeActorName() function since it will consistently change the name throughout all of the Dialogue System's subsystems, not just dialogue. The Dialogue System Extras page has a Discover Name Example (direct download) that demonstrates how to use ChangeActorName(). This example doesn't use Yarn, but since it's a Lua function you can use it like any other Yarn function in <<double-angle-brackets>>.
kko828
Posts: 17
Joined: Sun Nov 05, 2023 1:59 am

Re: Yarn2: Override actor's name?

Post by kko828 »

Hi, thank you for your reply.
I tried ChangeActorName() but it parsed strangely and gave me an error when running play mode.

my .yarn file:
Screenshot 2023-11-12 221346.png
Screenshot 2023-11-12 221346.png (3.12 KiB) Viewed 928 times
it parsed as :
Screenshot 2023-11-12 221507.png
Screenshot 2023-11-12 221507.png (3.7 KiB) Viewed 928 times
And i got this error:
Screenshot 2023-11-12 221641.png
Screenshot 2023-11-12 221641.png (117.54 KiB) Viewed 928 times
Please tell me the correct way to write this command when using it with Yarn.

Also, I have an additional question.
Is there a way to access tags written in Yarn (such as #some_metadata)?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Yarn2: Override actor's name?

Post by Tony Li »

Hi,

Yarn's syntax for functions is strange. Unlike standard languages such as C# and Lua, it doesn't use parentheses and commas. Try this:

Code: Select all

<<ChangeActorName MyCharacter ???>>
kko828
Posts: 17
Joined: Sun Nov 05, 2023 1:59 am

Re: Yarn2: Override actor's name?

Post by kko828 »

Hi, thank you for your reply.
I tried your code and it works! :D

Also, I have an additional question.
Is there a way to access tags written in Yarn (such as #some_metadata)?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Yarn2: Override actor's name?

Post by Tony Li »

Doh, sorry, I forgot to answer that part. There isn't currently a way, but I'll add it in the next release. (I also plan to add support for the new [pause/] marker and custom markup palette tags.)
kko828
Posts: 17
Joined: Sun Nov 05, 2023 1:59 am

Re: Yarn2: Override actor's name?

Post by kko828 »

Wow, thank you very much. i look forward to the next release! :D
kko828
Posts: 17
Joined: Sun Nov 05, 2023 1:59 am

Re: Yarn2: Override actor's name?

Post by kko828 »

Hi, I'm facing the command parsing problem again.

My yarn file:

Code: Select all

<<mmAddItem MainInventory Apple 1)>>
Unity Error Message:
Dialogue System: Lua code 'mmAddItem('MainInventory', 'Apple', '1)')' threw exception 'Object of type 'System.String' cannot be converted to type 'System.Double'.'

It seems that the third argument is parsed as String. How can I pass non-string variable to Lua function via Yarn file?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Yarn2: Override actor's name?

Post by Tony Li »

Hi,

Remove the ')'

Instead of this:

Code: Select all

<<mmAddItem MainInventory Apple 1)>>
use this:

Code: Select all

<<mmAddItem MainInventory Apple 1>>
kko828
Posts: 17
Joined: Sun Nov 05, 2023 1:59 am

Re: Yarn2: Override actor's name?

Post by kko828 »

Ahhhh that's a stupid mistake... :oops: Thank you, I fixed the code and it worked.
Post Reply