Losing the Next Button after Compile

Hi,

When I play the game in Unity I am able to see my next button:

image

However when I play the game after compiling, the button does not appear.

image

Can you please tell me how I can troubleshoot why? Thanks

I have just found this link to the solution Dialogues on build - Unity Courses / Ask - GameDev.tv

The button now works.

My new issue is relating to the conditions on what dialogue to appear. The system seems to randomly select the dialogue vs. showing the specific dialogue for set conditions.

As an example, I am getting the below dialogue:

But I should only get that dialogue if I have a specific weapon:

Here is the code from Equipment:

        public bool? Evaluate(string predicate, string[] parameters)
        {
            if (predicate == "HasItemEquipped")
            {
                foreach (var item in equippedItems.Values)
                {
                    if (item.GetItemID() == parameters[0])
                    {
                        return true;
                    }
                }
                return false;
            }
            return null;
        }

and here is the code from IPredicateEvaluator:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

namespace GameDevTV.Utils

{

    public interface IPredicateEvaluator

    {

        bool? Evaluate (string predicate, string[] parameters);

    }

}

Thanks for your help

Most often, this is an error in the Condition.cs script, let’s take a look at that one as well.

Good thinking, here you go:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace GameDevTV.Utils
{
    [System.Serializable]
    public class Condition
    {
        [SerializeField]
        Disjunction[] and;

        public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
        {
            foreach (Disjunction dis in and)
            {
                if (!dis.Check(evaluators))
                {
                    return false;
                }
            }
            return true;
        }

        [System.Serializable]
        class Disjunction
        {
            [SerializeField]
            Predicate[] or;

            public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
            {
                foreach (Predicate pred in or)
                {
                    if (pred.Check(evaluators))
                    {
                        return true;
                    }
                }
                return false;
            }
        }

        [System.Serializable]
        class Predicate
        {
            [SerializeField]
            string predicate;
            [SerializeField]
            string[] parameters;
            [SerializeField]
            bool negate = false;

            public bool Check(IEnumerable<IPredicateEvaluator> evaluators)
            {
                foreach (var evaluator in evaluators)
                {
                    bool? result = evaluator.Evaluate(predicate, parameters);
                    if (result == null)
                    {
                        continue;
                    }

                    if (result == negate) return false;
                }
                return true;
            }
        }
    }
}

Condition.cs is correct. That means we need to look at PlayerConversant next.

1 Like

Apologies for the late reply - I was travelling with work and away from my PC.

You are absolutely correct again Brian!

I had incorrectly tried to return GetComponent vs. GetComponents. The system was just finding the first available response and returning it vs. actually searching for the correct one. A tardy error.

The correct script:

    private IEnumerable<IPredicateEvaluator> GetEvaluators()
    {
        return GetComponents<IPredicateEvaluator>();
    }

my script:

    private IEnumerable<IPredicateEvaluator> GetEvaluators()
    {
        yield return GetComponent<IPredicateEvaluator>();
    }

Thanks Brian!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms