From 57a688f320f4424ae08f9db853c7708492c3ed98 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Sun, 3 Jun 2018 10:37:18 +1000 Subject: [PATCH] ElseIfs now confirm that the previous condition was at the same indent as themselves. -Corrects elifs from pairing incorrectly with nested ifs prior to themselves -Thanks to Wolfrug on the forum http://fungusgames.com/forum#!/support-questions:if-else-bug --- Assets/Fungus/Scripts/Commands/Condition.cs | 5 ++++- Assets/Fungus/Scripts/Components/Block.cs | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Assets/Fungus/Scripts/Commands/Condition.cs b/Assets/Fungus/Scripts/Commands/Condition.cs index a8dacb34..26e14bc8 100644 --- a/Assets/Fungus/Scripts/Commands/Condition.cs +++ b/Assets/Fungus/Scripts/Commands/Condition.cs @@ -59,8 +59,11 @@ namespace Fungus else { System.Type previousCommandType = ParentBlock.GetPreviousActiveCommandType(); + var prevCmdIndent = ParentBlock.GetPreviousActiveCommandIndent(); - if (previousCommandType.IsSubclassOf(typeof(Condition))) + //handle our matching if or else if in the chain failing and moving to us, + // need to make sure it is the same indent level + if (prevCmdIndent == IndentLevel && previousCommandType.IsSubclassOf(typeof(Condition))) { // Else If behaves the same as an If command EvaluateAndContinue(); diff --git a/Assets/Fungus/Scripts/Components/Block.cs b/Assets/Fungus/Scripts/Components/Block.cs index 8fba6b91..c2d76d30 100644 --- a/Assets/Fungus/Scripts/Components/Block.cs +++ b/Assets/Fungus/Scripts/Components/Block.cs @@ -355,6 +355,17 @@ namespace Fungus return null; } + public virtual int GetPreviousActiveCommandIndent() + { + if (previousActiveCommandIndex >= 0 && + previousActiveCommandIndex < commandList.Count) + { + return commandList[previousActiveCommandIndex].IndentLevel; + } + + return -1; + } + /// /// Recalculate the indent levels for all commands in the list. ///