From e703e3ed94e00c699da4a5ac9f5daea50845adfa Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 25 Apr 2014 18:09:41 +0100 Subject: [PATCH] Added SetString and GetString commands. --- .../Fungus/Scripts/Commands/GameCommands.cs | 26 ++++++++++++++++++- Assets/Fungus/Scripts/GameController.cs | 22 ++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Assets/Fungus/Scripts/Commands/GameCommands.cs b/Assets/Fungus/Scripts/Commands/GameCommands.cs index 26bdb891..693e97dd 100644 --- a/Assets/Fungus/Scripts/Commands/GameCommands.cs +++ b/Assets/Fungus/Scripts/Commands/GameCommands.cs @@ -142,7 +142,7 @@ namespace Fungus } /** - * Sets a globally accessible game value + * Sets a globally accessible integer value */ public class SetValue : CommandQueue.Command { @@ -164,5 +164,29 @@ namespace Fungus } } } + + /** + * Sets a globally accessible string value + */ + public class SetString : CommandQueue.Command + { + string key; + string value; + + public SetString(string _key, string _value) + { + key = _key; + value = _value; + } + + public override void Execute(CommandQueue commandQueue, Action onComplete) + { + Game.GetInstance().stringTable.SetString(key, value); + if (onComplete != null) + { + onComplete(); + } + } + } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/GameController.cs b/Assets/Fungus/Scripts/GameController.cs index 7526ecb4..d80ca9b4 100644 --- a/Assets/Fungus/Scripts/GameController.cs +++ b/Assets/Fungus/Scripts/GameController.cs @@ -464,6 +464,28 @@ namespace Fungus return GetValue(key) != 0; } + /** + * Sets a globally accessible string value. + * This method returns immediately but it queues an asynchronous command for later execution. + * @param key The name of the value to set + * @param value The string value to set + */ + public static void SetString(string key, string value) + { + CommandQueue commandQueue = Game.GetInstance().commandQueue; + commandQueue.AddCommand(new Command.SetString(key, value)); + } + + /** + * Gets a globally accessible string value. + * @param key The name of the value + * @return The string value for this key, or the empty string if not previously set. + */ + public static string GetString(string key) + { + return Game.GetInstance().stringTable.GetString(key); + } + #endregion #region Sprite Methods