Browse Source

Merge pull request #693 from stevehalliwell/NestedIfIntoElifBug

ElseIfs now confirm that the previous condition was at the same indent as themselves.
master
Chris Gregan 7 years ago committed by GitHub
parent
commit
31231b4437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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
{
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();

11
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;
}
/// <summary>
/// Recalculate the indent levels for all commands in the list.
/// </summary>

Loading…
Cancel
Save