diff --git a/Assets/Fungus/FungusScript/Commands/Reset.cs b/Assets/Fungus/FungusScript/Commands/Reset.cs index fd5c7441..903ac723 100644 --- a/Assets/Fungus/FungusScript/Commands/Reset.cs +++ b/Assets/Fungus/FungusScript/Commands/Reset.cs @@ -6,12 +6,16 @@ namespace Fungus { [CommandInfo("Scripting", "Reset", - "Resets state of all commands and variables in this Fungus Script.")] + "Resets the state of all commands and local and global variables in the Fungus Script.")] public class Reset : Command { + public bool resetCommands = true; + public bool resetLocalVariables = true; + public bool resetGlobalVariables = true; + public override void OnEnter() { - GetFungusScript().Reset(); + GetFungusScript().Reset(resetCommands, resetLocalVariables, resetGlobalVariables); Continue(); } diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index 16d88595..139d0cce 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -409,17 +409,29 @@ namespace Fungus } } - public virtual void Reset() + public virtual void Reset(bool resetCommands, bool resetLocalVariables, bool resetGlobalVariables) { - Command[] commands = GetComponentsInChildren(); - foreach (Command command in commands) + if (resetCommands) { - command.OnReset(); + Command[] commands = GetComponentsInChildren(); + foreach (Command command in commands) + { + command.OnReset(); + } } foreach (Variable variable in variables) { - variable.OnReset(); + if (resetLocalVariables && + variable.scope == VariableScope.Local) + { + variable.OnReset(); + } + else if (resetGlobalVariables && + variable.scope == VariableScope.Global) + { + variable.OnReset(); + } } } }