diff --git a/Assets/Fungus/Scripts/Commands/VariableCondition.cs b/Assets/Fungus/Scripts/Commands/VariableCondition.cs index f3645602..78970e24 100644 --- a/Assets/Fungus/Scripts/Commands/VariableCondition.cs +++ b/Assets/Fungus/Scripts/Commands/VariableCondition.cs @@ -26,6 +26,7 @@ namespace Fungus } } + // anyone with a better name for this can update it public enum AnyOrAllConditions @@ -41,7 +42,27 @@ namespace Fungus [SerializeField] protected AnyOrAllConditions anyOrAllConditions; - [SerializeField] protected List conditions = new List(); + [SerializeField] protected List conditions = new List(); + + + /// + /// Called when the script is loaded or a value is changed in the + /// inspector (Called in the editor only). + /// + public override void OnValidate() + { + base.OnValidate(); + + if (conditions == null) + { + conditions = new List(); + } + + if (conditions.Count == 0) + { + conditions.Add(new conditionExpression()); + } + } protected override bool EvaluateCondition() { @@ -61,7 +82,6 @@ namespace Fungus continue; } condition.AnyVar.Compare(condition.CompareOperator, ref curResult); - Debug.Log("res : " + curResult.ToString()); resultAll &= curResult; resultAny |= curResult; } @@ -73,13 +93,15 @@ namespace Fungus protected override bool HasNeededProperties() { - if( conditions == null || conditions.Count == 0){ + if (conditions == null || conditions.Count == 0) + { return false; } foreach (conditionExpression condition in conditions) { - if(condition.AnyVar == null || condition.AnyVar.variable == null){ + if (condition.AnyVar == null || condition.AnyVar.variable == null) + { return false; } @@ -105,28 +127,26 @@ namespace Fungus string summary = ""; string connector = ""; - if(anyOrAllConditions == AnyOrAllConditions.AnyOneTrue){ + if (anyOrAllConditions == AnyOrAllConditions.AnyOneTrue) + { connector = " Or "; } - else{ + else + { connector = " And "; } - for(int i = 0 ; i < conditions.Count; i++) + for (int i = 0 ; i < conditions.Count; i++) { summary += conditions[i].AnyVar.variable.Key + " "; summary += VariableUtil.GetCompareOperatorDescription(conditions[i].CompareOperator) + " "; summary += conditions[i].AnyVar.GetDataDescription(); - if(i