Browse Source

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
master
desktop-maesty/steve 7 years ago
parent
commit
57a688f320
  1. 5
      Assets/Fungus/Scripts/Commands/Condition.cs
  2. 11
      Assets/Fungus/Scripts/Components/Block.cs

5
Assets/Fungus/Scripts/Commands/Condition.cs

@ -59,8 +59,11 @@ namespace Fungus
else else
{ {
System.Type previousCommandType = ParentBlock.GetPreviousActiveCommandType(); 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 // Else If behaves the same as an If command
EvaluateAndContinue(); EvaluateAndContinue();

11
Assets/Fungus/Scripts/Components/Block.cs

@ -355,6 +355,17 @@ namespace Fungus
return null; return null;
} }
public virtual int GetPreviousActiveCommandIndent()
{
if (previousActiveCommandIndex >= 0 &&
previousActiveCommandIndex < commandList.Count)
{
return commandList[previousActiveCommandIndex].IndentLevel;
}
return -1;
}
/// <summary> /// <summary>
/// Recalculate the indent levels for all commands in the list. /// Recalculate the indent levels for all commands in the list.
/// </summary> /// </summary>

Loading…
Cancel
Save