From b24197beec4a805c4c56c05a4144a2270a234cf0 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 16 Jan 2015 21:42:25 +0000 Subject: [PATCH] Change #70 Added FungusScript.GetVariable() method --- .../FungusScript/Scripts/FungusScript.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index de88a1ae..d975f57d 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -265,6 +265,25 @@ namespace Fungus } } + /** + * Returns the variable with the specified key, or null if the key is not found. + * You can then access the variable's value using the Value property. e.g. + * BooleanVariable boolVar = fungusScript.GetVariable("MyBool"); + * boolVar.Value = false; + */ + public T GetVariable(string key) where T : Variable + { + foreach (Variable variable in variables) + { + if (variable.key == key) + { + return variable as T; + } + } + + return null; + } + /** * Gets a list of all variables with public scope in this Fungus Script. */