protected bool TrySetValue(VariableStorageBehaviour source, string variableName, Value value) { try { source.SetValue(variableName, value); return(true); } catch (SystemException ex) when(ex is ArgumentException || ex is InvalidOperationException) { // The source was not compatible with the value. Try another. // Log the exception if the flag is set to true if (logSetKnownErrors) { Debug.LogException(ex); } } return(false); }
public void Select(VariableStorageBehaviour variableStorage) => Select(sources.IndexOf(variableStorage));
// [YarnCommand("Morale_Down")] // public void Morale_Down_Test(){ // morale_test--; // } // Start is called before the first frame update void Start() { varStore = runner.variableStorage; }
public static void SetValueNoLeading(this VariableStorageBehaviour v, string variableNameNoLeading, Value value) => v.SetValue(AddLeadingIfNeeded(variableNameNoLeading), value);
public static Value GetValueNoLeading(this VariableStorageBehaviour v, string variableNameNoLeading) => v.GetValue(AddLeadingIfNeeded(variableNameNoLeading));
public static string RemoveLeadingIfPresent(this VariableStorageBehaviour _, string text) => RemoveLeadingIfPresent(text);
public static string AddLeadingIfNeeded(this VariableStorageBehaviour _, string text) => AddLeadingIfNeeded(text);
// Start is called before the first frame update void Start() { _spawned = false; DeactivateSuns(); _varStorage = GameObject.FindObjectOfType <VariableStorageBehaviour>().GetComponent <VariableStorageBehaviour>(); }
/// <summary> /// Replaces all var names in the passed text with their values as drawn from the /// passed variable storage. /// </summary> /// <param name="variableStorage"></param> /// <param name="text"></param> /// <returns></returns> public static string ParseYarnText(VariableStorageBehaviour variableStorage, string text) { Debug.Log("Calling YarnUtils' ParseYarnText!"); StringBuilder result = new StringBuilder(); string textToParse = string.Copy(text); string temp; char varMarker = '$'; char unVarMarker = '/'; int varMarkerIndex = textToParse.IndexOf(varMarker); StringBuilder varName = new StringBuilder(); string varValue; while (varMarkerIndex > -1) { /*Stuff checking whether or not to ignore a var name. WIP * // Check if this marker is supposed to actually mark a var; if it isn't, there will be * // just one forward slash in front of it. * bool slashBeforeVar = varMarkerIndex > 0 && * textToParse[varMarkerIndex - 1] == unVarMarker; * bool negateSlash = slashBeforeVar && varMarkerIndex > 1 && * textToParse[varMarkerIndex - 2] == unVarMarker; * * if (slashBeforeVar && !negateSlash) * { * // Remove the forward slash, and find the next var marker * textToParse = textToParse.RemoveAt('/', varMarkerIndex - 1); * * varMarkerIndex = textToParse.Substring(varMarkerIndex + 2).IndexOf(varMarker); * continue; * } */ // Add all the text before the var marker to the result, trimming it out of the text // to parse temp = textToParse.Substring(0, varMarkerIndex); textToParse = textToParse.Substring(varMarkerIndex); result.Append(temp); // replace all double-slashes in the temp (//) with single-slashes temp = temp.Replace("//", "/"); // Get the whole variable name from the remaining text // (Keep in mind var names can only have letters and/or digits) do { varName.Append(textToParse[0]); textToParse = textToParse.Remove(0, 1); }while (textToParse.Length > 0 && char.IsLetterOrDigit(textToParse[0])); // Get the value from the variable storage, and add it to the result varValue = variableStorage.GetValue(varName.ToString()).AsString; result.Append(varValue); varName = new StringBuilder(); // update the var marker index varMarkerIndex = textToParse.IndexOf(varMarker); } if (textToParse.Length > 0) { result.Append(textToParse); } return(result.ToString()); }