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:
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)"
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.
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);
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.
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.
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?
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:
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.
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.:
<<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.
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: