Page 1 of 2

Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sat Jan 01, 2022 9:16 pm
by hearsedriver
Hi Tony,

Happy New Year!

I've installed YarnSpinner 2.0.1 using OUPM as advised on their website in order to test it separately.

I have then upgraded to Dialogue System for Unity 2.2.23 and enabled the Yarn importer to give it a try on an existing Dialogue System for Unity project. Unfortunately YarnProject.cs won't compile due to:

Code: Select all

Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Editor/Tools/Importers/Yarn/YarnProject.cs(791,26): error CS0117: 'Compiler' does not contain a definition for 'CompileFile'
Indeed, the only matching method signature I can find is "CompilationResult Compile (CompilationJob compilationJob)"

Please advise.

Best regards

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sat Jan 01, 2022 9:35 pm
by Tony Li
Hi,

The Dialogue System's Yarn importer works with Yarn Spinner 1.2.7. We're working on updating it for Yarn Spinner 2.x, which just came out a little more than a week ago.

Sorry for the confusion. I just noticed that the announcement message and the video tutorial were updated to clarify that it's currently for Yarn Spinner 1.2.7, but the updated manual page wasn't published. I'll publish it now.

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sat Jan 01, 2022 9:40 pm
by hearsedriver
FYI I've made a small modification:

Code: Select all

            foreach (var filename in filenames)
            {
                if (_prefs.debug) Debug.Log("Parsing Yarn program found at: " + filename);
                //var program = new Program();
                //var stringTable = new Dictionary<string, StringInfo>() as IDictionary<string, StringInfo>;
                var job = CompilationJob.CreateFromFiles(filename);
                var result = Compiler.Compile(job);
                var stringTable = result.StringTable;
                var program = result.Program;
                //Compiler.CompileFile(filename, out program, out stringTable);
                if (_prefs.debug) Debug.Log("Yarn program name: " + program.Name + " nodes: " + program.Nodes.Count);
After that, I run into another problem:

Code: Select all

Assets/Scripts/YarnCustomCommands.cs(134,35): error CS0117: 'Dialogue' does not contain a definition for 'ExpandFormatFunctions'

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sat Jan 01, 2022 9:41 pm
by hearsedriver
Tony Li wrote: Sat Jan 01, 2022 9:35 pm Hi,

The Dialogue System's Yarn importer works with Yarn Spinner 1.2.7. We're working on updating it for Yarn Spinner 2.x, which just came out a little more than a week ago.

Sorry for the confusion. I just noticed that the announcement message and the video tutorial were updated to clarify that it's currently for Yarn Spinner 1.2.7, but the updated manual page wasn't published. I'll publish it now.
Aaah, that clarifies the matter, thank you! I installed the latest version without thinking about it. I'll give 1.2.7 a try then.

Thanks again!

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sat Jan 01, 2022 9:44 pm
by Tony Li
If you have any trouble installing the latest version, please see the screenshot that's now on the Yarn Spinner import page. I had uploaded the latest documentation but had forgotten to click Publish. :oops:

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sun Jan 02, 2022 12:42 pm
by hearsedriver
Switching the YarnSpinner version worked without issues.

It's probably worth a different thread but could you explain how I would access variables like "Item["Prop_sword"].Count" when using the Adventure Creator bridge?

Thanks!

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sun Jan 02, 2022 3:03 pm
by Tony Li
Hi,

There are a few angles to that question. I'll cover some. If I missed what you're looking for, please let me know.
  • In the Dialogue System (DS), a dialogue database has a list of variables, a list of items, a list of actors, etc.
  • If you're using the Yarn importer, in Yarn you can just use a variable without declaring it beforehand. When you import Yarn into a dialogue database, the importer will add those variables to the dialogue database's variables list.
  • At runtime, the Dialogue System runs Lua, which is a simple scripting environment. The advantage of Lua is that it gives you the power to specify logic of any complexity. (You don't actually have to do any Lua scripting, but it's available as an option.)
    • When DS starts, it loads all of the dialogue database variables, items, etc., into Lua.
    • You can access variables in Lua by entering Lua code such as Variable["Age"] = 21 or by using "..." dropdown menus to automatically generate Lua code so you don't have to do any scripting.
    • You can also access variables in C# code using the DialogueLua class, such as:

      Code: Select all

      int age = DialogueLua.GetVariable("Age").asInt;
    • Similarly, you can access item data in Lua by typing things like: Item["Prop_sword"].Count or by using dropdown menus.
  • Adventure Creator (AC) also has its own list of variables and items, separate from the Dialogue System.
  • By default, when a conversation starts the Adventure Creator Bridge copies all AC variables and item data to the Dialogue System's Lua environment.
  • When a conversation ends, the Adventure Creator Bridge copies the values of those variables and item data from the Dialogue System's Lua environment back to AC.
  • So if you change a DS variable or item data during a conversation -- for example, give the player a sword using Item["Prop_sword"].Count = 1 -- then at the end of the conversation this info will be reflected back to AC.
  • The DS-AC integration also has an edit-time utility to copy all DS variables into AC's variable list.

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sun Jan 02, 2022 3:50 pm
by hearsedriver
Thanks for your thorough response, Tony. It covers a lot, yet I was looking at it from the angle of a Yarn dialogue file.

From what I've seen, the crux seems to be that YarnSpinner only supports primitive types. It does not seem to allow for more complex structures like structs/arrays/maps/tables. Conditional blocks which need access to more sophisticated structures won't work, e.g.:

Code: Select all

<<if $Item["Prop_sword"].Count == 0>>
NPC: You are unarmed!
<<endif>>
Are you seeing a possible workaround to overcome this? I understand that this is a restriction of the YarnSpinner compiler, to begin with: it doesnt' allow any special characters in variable names. So maybe one way could be to provide an indirection where e.g. a variable prefixed with e.g. "lua_" could be looked up dynamically, like "lua_Item__Prop_sword__Count", but I am not sure if this could be hooked into DS easily.

Thanks!

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Sun Jan 02, 2022 4:18 pm
by Tony Li
Hi,

Yes, this is a limitation of Yarn. However, as we add support for Yarn Spinner 2.x, we're going to add a built-in custom command to run Lua code. So you should be able to include something like:

Code: Select all

<<lua "Item['Prop_sword'].Count = 1">>
If Yarn 2.x still doesn't support commands in <<if>> conditions, conditional blocks will have to look something like:

Code: Select all

<<lua "return Item['Prop_sword'].Count">>
<<if $LuaResult == 0>>
NPC: You are unarmed!
<<endif>>

Re: Yarn import doesn't compile with YarnSpinner 2.0.1

Posted: Wed May 25, 2022 6:41 pm
by wedgiebee
Hi Tony, are there still plans to update the package to import the latest version of Yarn Spinner? They're currently on 2.2!