diff --git a/Assets/Fungus/FungusScript/Commands/Else.cs b/Assets/Fungus/FungusScript/Commands/Else.cs index 1f10e185..d999aec1 100644 --- a/Assets/Fungus/FungusScript/Commands/Else.cs +++ b/Assets/Fungus/FungusScript/Commands/Else.cs @@ -12,9 +12,32 @@ namespace Fungus.Script { public override void OnEnter() { - Continue(); - } + // Find the next EndIf command at the same indent level as this Else command + bool foundThisCommand = false; + int indent = indentLevel; + foreach(FungusCommand command in parentSequence.commandList) + { + if (foundThisCommand && + command.indentLevel == indent) + { + System.Type type = command.GetType(); + if (type == typeof(EndIf)) + { + // Execute command immediately after the EndIf command + Continue(command); + return; + } + } + else if (command == this) + { + foundThisCommand = true; + } + } + // No matching EndIf command found, so just stop the sequence + Stop(); + } + public override int GetPreIndent() { return -1; diff --git a/Assets/Fungus/FungusScript/Commands/If.cs b/Assets/Fungus/FungusScript/Commands/If.cs index 7eb1bd64..d36d1018 100644 --- a/Assets/Fungus/FungusScript/Commands/If.cs +++ b/Assets/Fungus/FungusScript/Commands/If.cs @@ -16,7 +16,7 @@ namespace Fungus.Script [CommandInfo("Scripting", "If", - "Execute another sequence IF a condition is true. Sequences can be specified for both true (THEN) and false (ELSE) conditions.", + "If the test expression is true, execute the following block of commands.", 253, 253, 150)] public class If : FungusCommand { @@ -32,10 +32,6 @@ namespace Fungus.Script public StringData stringValue; - public Sequence thenSequence; - - public Sequence elseSequence; - public override void OnEnter() { bool condition = false; @@ -135,36 +131,38 @@ namespace Fungus.Script if (condition) { - if (thenSequence != null) - { - ExecuteSequence(thenSequence); - return; - } + Continue(); } else { - if (elseSequence != null) + // Find the next Else or EndIf command at the same indent level as this If command + bool foundThisCommand = false; + int indent = indentLevel; + foreach(FungusCommand command in parentSequence.commandList) { - ExecuteSequence(elseSequence); - return; + if (foundThisCommand && + command.indentLevel == indent) + { + System.Type type = command.GetType(); + if (type == typeof(Else) || + type == typeof(EndIf)) + { + // Execute command immediately after the Else or EndIf command + Continue(command); + return; + } + } + else if (command == this) + { + foundThisCommand = true; + } } - } - Continue(); - } - - public override void GetConnectedSequences(ref List connectedSequences) - { - if (thenSequence != null) - { - connectedSequences.Add(thenSequence); - } - if (elseSequence != null) - { - connectedSequences.Add(elseSequence); + // No matching EndIf command found, so just stop the sequence + Stop(); } } - + public override string GetSummary() { if (variable == null) @@ -212,26 +210,6 @@ namespace Fungus.Script summary += stringValue.GetDescription(); } - summary += " THEN "; - - if (thenSequence == null) - { - summary += ""; - } - else - { - summary += thenSequence.name; - } - summary += " ELSE "; - if (elseSequence == null) - { - summary += ""; - } - else - { - summary += elseSequence.name; - } - return summary; } diff --git a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs index 463177e5..64807a53 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusScriptEditor.cs @@ -26,7 +26,14 @@ namespace Fungus.Script if (Application.isPlaying) { - t.selectedCommand = t.executingSequence.activeCommand; + if (t.executingSequence == null) + { + t.selectedCommand = null; + } + else + { + t.selectedCommand = t.executingSequence.activeCommand; + } } EditorGUI.BeginChangeCheck(); diff --git a/Assets/Fungus/FungusScript/Editor/IfEditor.cs b/Assets/Fungus/FungusScript/Editor/IfEditor.cs index 0dbd02ab..b4f56a5b 100644 --- a/Assets/Fungus/FungusScript/Editor/IfEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/IfEditor.cs @@ -76,29 +76,6 @@ namespace Fungus.Script EditorGUILayout.PropertyField(serializedObject.FindProperty("stringValue")); } - EditorGUILayout.Separator(); - - Sequence thenSequence = SequenceEditor.SequenceField(new GUIContent("Then", "Sequence to execute if comparision is true"), - new GUIContent(""), - t.GetFungusScript(), - t.thenSequence); - - Sequence elseSequence = SequenceEditor.SequenceField(new GUIContent("Else", "Sequence to execute if comparision is false"), - new GUIContent(""), - t.GetFungusScript(), - t.elseSequence); - - if (thenSequence != t.thenSequence) - { - Undo.RecordObject(t, "Set Then Sequence"); - t.thenSequence = thenSequence; - } - if (elseSequence != t.elseSequence) - { - Undo.RecordObject(t, "Set Else Sequence"); - t.elseSequence = elseSequence; - } - serializedObject.ApplyModifiedProperties(); } } diff --git a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs index 99de459e..333fb9f8 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusCommand.cs @@ -80,9 +80,14 @@ namespace Fungus.Script } public virtual void Continue() + { + Continue(this); + } + + public virtual void Continue(FungusCommand currentCommand) { OnExit(); - parentSequence.ExecuteNextCommand(this); + parentSequence.ExecuteNextCommand(currentCommand); } public virtual void Stop() diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index ab132107..2ce356e1 100644 Binary files a/Assets/Shuttle/ShuttleGame.unity and b/Assets/Shuttle/ShuttleGame.unity differ