Skip to content

I can get this working, almost. Question, how do I send in variables? #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
FMastro opened this issue Aug 3, 2020 · 3 comments
Open

Comments

@FMastro
Copy link

FMastro commented Aug 3, 2020

My Dialogue Tree starts with a condition check "Round=1" in the first node. It's also part of the variable database in the dialogue.
Edith.json.txt

In code I have..

_dp.IntVariables["Round"] = 1;

but doesn't seem to have any affect on the conversation. Thoughts?

Update: Seems to not work with any variables. I tried a boolean. In the DD I put "firsttime" then I tried "firsttime=True" and "firsttime==True" and with lower case "true"

I also looked into the OnEvaulateCondition override but it doesn't tell me if it's a boolean, int or string. So I don't know what dictionary to look in. Would be nice if the sender somehow mentioned that. I checked the currentNode too and it just says it's a condition node but doesn't tell you what type. then I could make it myself. For now I'll have to just keep unique keys and search each dict to find the key. I'll try that since I can't get this to evaluate at all anything I put in.

@FMastro
Copy link
Author

FMastro commented Aug 3, 2020

I can't get any type of variable/condition working out of the box with DD and this tool. I must be missing something. So I overrode the evaluation method but I had to based on very simple variables in DD and I'm not checking for string. Just int and bool

In DD I only use two options:
for int I use variable=int ex. Round=1 or Score=10
for bool I just use a name ex. HasSpoken

So this doesn't work for anything else like greater then or less then or not equal

private bool OnEvaluateCondition(DialoguePlayer sender, string script)
        {
            //check if there's an =, if not then it's boolean. otherwise it was an int.
            if (script.Contains("="))
            {
                var values = script.Split('=');
                var varName = values[0];
                var varValue = int.Parse(values[1]);
                return _dp.IntVariables[varName] == varValue;
            }
            else
            {
                return _dp.BoolVariables[script];
            }
        }

@ThePhilipBooker
Copy link

I can't get any type of variable/condition working out of the box with DD and this tool. I must be missing something. So I overrode the evaluation method but I had to based on very simple variables in DD and I'm not checking for string. Just int and bool

In DD I only use two options:
for int I use variable=int ex. Round=1 or Score=10
for bool I just use a name ex. HasSpoken

So this doesn't work for anything else like greater then or less then or not equal

private bool OnEvaluateCondition(DialoguePlayer sender, string script)
        {
            //check if there's an =, if not then it's boolean. otherwise it was an int.
            if (script.Contains("="))
            {
                var values = script.Split('=');
                var varName = values[0];
                var varValue = int.Parse(values[1]);
                return _dp.IntVariables[varName] == varValue;
            }
            else
            {
                return _dp.BoolVariables[script];
            }
        }

Thank you so much this saved me hours of work!

@ThePhilipBooker
Copy link

ThePhilipBooker commented Aug 3, 2021

I iterated further on @FMastro's code so that you can now set values within Dialogue Designer and parse them into your game. This allows you to have values set within the dialogue json instead of needing to set them externally. Here's how:

  1. I add an execute node to my DD json file any time I need to set a value within the dialogue (you can see the example attached)
    tryingconditional.json.txt

  2. I then add a variable and assign it a value within the execute node. To keep it simple and in line with FMastro's code, I used a similar format but changed it slightly for the purposes of my needs within the execute node. In this case my code uses variable=bool ex. insulted=true. (obviously this means if you need to set other types of variables, you will need to further iterate on this code, but this will at least get you headed in the right direction.)

  3. in my script that handles NPC interactions I added the code below, using a mix of FMastro and BrianMacIntosh's code

//call OnExecuteScript method
private void OnExecuteScript(DialoguePlayer sender, string script)
    {
        //parse varables from DD json file (script)
        var values = script.Split('=');
        var varName = values[0];
        var varValue = bool.Parse(values[1]);
        /*Check if my Dialogue Dictionary already has the key that was just parsed, 
           if it does, assign it the new parsed value, if it doesn't add the new parsed key 
           and the new parsed value*/
        if (PlayerNPCInteractions.DV.DialogueBools.ContainsKey(varName))
        {
            PlayerNPCInteractions.DV.DialogueBools[varName] = varValue;
        }
        else
        {
            PlayerNPCInteractions.DV.DialogueBools.Add(varName,varValue);
            
        }

Email me if you have questions, I know how confusing all of this can be when you first get started. At first, I didnt even realize FMastro was using a dictionary! Yeesh!

-Philip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants