Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Fleece

A dialogue manager for Unity that doesn't fray at the edges. · By KaiClavier

How to define custom evaluations like <<coin()>> or <!visited("NameOfPassage")>>

A topic by Edmango created Nov 01, 2019 Views: 363 Replies: 5
Viewing posts 1 to 3
(1 edit)

Hello again! My sincerest apologies for making another post so soon after the last one. 
I was browsing through the documentation and noticed that there was a feature for defining and checking the value of variables, I wanted to use this to similar effect of the <<!visited("passagename")>>, only by allowing it to gather data from a script and checking if an item or character was in an array.

I've been using the FleeceVisualNovelExample as a template for this so far and making my commands through the bool RunCommand()

However, when I tried to make something like <coin()> from the shop example, that would use commandInsertString to leave a "true" or "false" statement behind, thus allowing me to run a check for if player A had Item "the mcguffin", Then it would come up as true and the dialogue would progress as normal.

However when I did this, it turned out /ALL/ my results came back true. This is because I made it in a separate script, my own "VN" script, which is not the parser or default parser scripts and I'm not sure what I need to override so that I can make a function similar to those. Especially since the DefaultParser and Parser classes are inherited, so I can't just put one in the scene and give it a variable that lets it access my player stats script in the scene.

TLDR:
I'd like to know how to make something like <<Coin()>> or <<visited("nameOfPassage")>> in a separate script, like in the FleeceVisualNovelExample so that I can reference other public variables and not have to instantiate them at the beginning of dialogue. And then use these to allow or disallow players to see certain dialogue chains.


I'd appreciate any assistance in the matter, or to be pointed in the right direction on how to resolve this. Thanks.

Developer

Hey!

Quick ideas, bere…

If you havent discovered it yet, the visualnovelexample uses the drawstring class to manage custom commands… so you can subscribe the the delegate event there to add custom commands that do whatever you want.

I think that would be what youre after? Parsers have project-wide commands, Drawstrings have dialogue box-based commands, which can tie into monobehaviours more easily.

Also, its possible to override a parser so that variables work as commands too… for instance, $myVariable could return any value if overridden, not just a stored one

(1 edit)

Thanks for the reply, I'm having a little difficulty wrapping my head around how to do this.

From what you said, inside of the visualnovelexample you use the drawstring class to manage custom commands. I believe you are referring to the following:

You subscribe to that delegate event by using the drawstring.RunCommandEvent+=Runcommand; and it leads me to this line


By following that rabbit hole to the drawtring script I see an event called RunCommandEvent and underneath that the bool for Runcommand()

Unfortunately that bool only lets me run commands in the "Raw Text" portion of the fleece dialogue line editor. Trying to put it in the "Link Raw Text" portions when you have a branching choice causes the text to not be read or parsed properly.

So now, after reading through your message several times, I've tried instead to look through the parsers and figure out how to resolve it that way. I found the "FleeceDefaultParser" that comes included with fleece and the script associated with it and am now trying to figure out how to implement something the returns "true" or "false"

I made a function "isLeader" to check if you had an object or leader of a specific type in the leader slot of FleeceDefaultParser (this is in the parser.cs file)
It checks and in the inspector displays it as FALSE if the leader is not correct (as intended)

However, whenever I test this in the live game it completely disregards the "False" text and plays that line of dialogue that should have been rejected. I haven't done anything different than you have for the visited or !visited line. Using a debug string prints out False which means it should technically be rejecting it. But it does not. I tried deleting those passages and making new ones but it still is rejecting it.

I followed the same format you set up and tried to establish things to be as close to how you did it as possible but was wondering if there was something super obveous I was missing, or perhaps it's that I just dont have a good enough foundation to understand how to make these kinds of edits.

Thanks for your time.

Okay, so after tinkering with it for a few hours I found out the problem. It's super strange. This is an example of what I had before


In the "Let's Test" passage I had a single line of text, then at the end of that it would check to see if that value was true.
BUT what ended up happening is that it would just pick the first link in the chain as if it said true. Now I tried this with the <<!visited>> function too, and it caused the same response which nearly caused me to tear my hair out because I saw it work before. So I tried this:



The only difference being that I put no input text on the first passage. If there's no text then it will check the values first and function properly. But if there's ANY TEXT AT ALL in the passage it refuses to acknowledge it.

I have no idea if I ran into an extremely fringe bug or I coded something strangely to cause this to happen.

Developer

I think this is the intended default behaviour, check out the docs for the section on “empty passage logic”.

If a passage does not have any text in it, when a parser reaches it, it will automatically follow the first link that evaluates to “True”, defaulting to the final link.

I'm realizing now I didnt reply to you earlier. Thank you for the reply and clarification!