Yarn2: Build-In Functions do not work

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

Yarn2: Build-In Functions do not work

Post by kko828 »

Hi, thank you for your continues support.

Today, I've tried several Built-In Functions in Yarn2, but none of them seem to work. Are these functions unavailable in your system?

Here's my .yarn file:

Code: Select all

title: BuildInFunc_Test
---
My lucky number is {random_range(1, 10)}!

<<if not visited("BuildInFunc_Test") >>
    This is your first visit.
<<elseif visited_count("BuildInFunc_Test") == 1>>
    This is your 2nd visit.
<<elseif visited_count("BuildInFunc_Test") == 2>>
    This is your 3rd visit.
<<else>>
    You have visited more than 4 times.
<<endif>>
===
The result is:
1. random_range(1, 10) is parsed as "{0}" when I import it into Dialogue System. The dialogue always says "My lucky number is {0}!"
2. visited() and visited_count() are parsed as Conditions when I import it, but they don't seem to work properly. The dialogue always says "You have visited more than 4 times."
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Yarn2: Build-In Functions do not work

Post by Tony Li »

Hi,

Did you add a YarnCustomCommands component (or a custom subclass) to your Dialogue Manager GameObject?

Are there any errors or warnings in the Console window?
kko828
Posts: 17
Joined: Sun Nov 05, 2023 1:59 am

Re: Yarn2: Build-In Functions do not work

Post by kko828 »

Oh, I didn't know i needed to add that component to DialogueManager.
I added the component and now it works.
thank you! :D
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Yarn2: Build-In Functions do not work

Post by Tony Li »

I'll clarify that in the manual. You're right; it's not clear at all.
Post Reply