From f23e5f192ab11b2ae778321961cdcfe7403aa89e Mon Sep 17 00:00:00 2001 From: Jorge Ramirez Date: Sun, 1 Apr 2018 16:37:28 -0400 Subject: [PATCH] Add error messages when using invalid variable operators --- .../Scripts/VariableTypes/BooleanVariable.cs | 20 +++++---- .../Scripts/VariableTypes/FloatVariable.cs | 43 +++++++++++-------- .../VariableTypes/GameObjectVariable.cs | 8 +++- .../Scripts/VariableTypes/IntegerVariable.cs | 43 +++++++++++-------- .../Scripts/VariableTypes/StringVariable.cs | 20 +++++---- 5 files changed, 78 insertions(+), 56 deletions(-) diff --git a/Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs b/Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs index 30cb3120..2c1da160 100644 --- a/Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs @@ -25,13 +25,15 @@ namespace Fungus switch (compareOperator) { - case CompareOperator.Equals: - condition = lhs == rhs; - break; - case CompareOperator.NotEquals: - default: - condition = lhs != rhs; - break; + case CompareOperator.Equals: + condition = lhs == rhs; + break; + case CompareOperator.NotEquals: + condition = lhs != rhs; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -41,13 +43,15 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; case SetOperator.Negate: Value = !value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs b/Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs index e64464f0..083e2528 100644 --- a/Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs @@ -38,24 +38,27 @@ namespace Fungus switch (compareOperator) { - case CompareOperator.Equals: - condition = lhs == rhs; - break; - case CompareOperator.NotEquals: - condition = lhs != rhs; - break; - case CompareOperator.LessThan: - condition = lhs < rhs; - break; - case CompareOperator.GreaterThan: - condition = lhs > rhs; - break; - case CompareOperator.LessThanOrEquals: - condition = lhs <= rhs; - break; - case CompareOperator.GreaterThanOrEquals: - condition = lhs >= rhs; - break; + case CompareOperator.Equals: + condition = lhs == rhs; + break; + case CompareOperator.NotEquals: + condition = lhs != rhs; + break; + case CompareOperator.LessThan: + condition = lhs < rhs; + break; + case CompareOperator.GreaterThan: + condition = lhs > rhs; + break; + case CompareOperator.LessThanOrEquals: + condition = lhs <= rhs; + break; + case CompareOperator.GreaterThanOrEquals: + condition = lhs >= rhs; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -65,7 +68,6 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; @@ -81,6 +83,9 @@ namespace Fungus case SetOperator.Divide: Value /= value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs b/Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs index 6b627563..f4b3538f 100644 --- a/Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs @@ -30,9 +30,11 @@ namespace Fungus condition = lhs == rhs; break; case CompareOperator.NotEquals: - default: condition = lhs != rhs; break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -42,10 +44,12 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs b/Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs index 52617eff..06726b58 100644 --- a/Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs @@ -38,24 +38,27 @@ namespace Fungus switch (compareOperator) { - case CompareOperator.Equals: - condition = lhs == rhs; - break; - case CompareOperator.NotEquals: - condition = lhs != rhs; - break; - case CompareOperator.LessThan: - condition = lhs < rhs; - break; - case CompareOperator.GreaterThan: - condition = lhs > rhs; - break; - case CompareOperator.LessThanOrEquals: - condition = lhs <= rhs; - break; - case CompareOperator.GreaterThanOrEquals: - condition = lhs >= rhs; - break; + case CompareOperator.Equals: + condition = lhs == rhs; + break; + case CompareOperator.NotEquals: + condition = lhs != rhs; + break; + case CompareOperator.LessThan: + condition = lhs < rhs; + break; + case CompareOperator.GreaterThan: + condition = lhs > rhs; + break; + case CompareOperator.LessThanOrEquals: + condition = lhs <= rhs; + break; + case CompareOperator.GreaterThanOrEquals: + condition = lhs >= rhs; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -65,7 +68,6 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; @@ -81,6 +83,9 @@ namespace Fungus case SetOperator.Divide: Value /= value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/StringVariable.cs b/Assets/Fungus/Scripts/VariableTypes/StringVariable.cs index 75921ef0..b9443aa1 100644 --- a/Assets/Fungus/Scripts/VariableTypes/StringVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/StringVariable.cs @@ -25,13 +25,15 @@ namespace Fungus switch (compareOperator) { - case CompareOperator.Equals: - condition = lhs == rhs; - break; - case CompareOperator.NotEquals: - default: - condition = lhs != rhs; - break; + case CompareOperator.Equals: + condition = lhs == rhs; + break; + case CompareOperator.NotEquals: + condition = lhs != rhs; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -41,10 +43,12 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } }