AGS.Types.Game.IsScriptNameAlreadyUsed C# (CSharp) Method

IsScriptNameAlreadyUsed() public method

public IsScriptNameAlreadyUsed ( string tryName, object ignoreObject ) : bool
tryName string
ignoreObject object
return bool
        public bool IsScriptNameAlreadyUsed(string tryName, object ignoreObject)
        {
            if (tryName == string.Empty)
            {
                return false;
            }

            foreach (string name in RESERVED_SCRIPT_NAMES)
            {
                if (tryName == name)
                {
                    return true;
                }
            }

            foreach (GUI gui in this.RootGUIFolder.AllItemsFlat)
            {
                if (gui != ignoreObject)
                {
                    if (gui.Name == tryName)
                    {
                        return true;
                    }

                    if (gui.Name.StartsWith("g") &&
                        (gui.Name.Length > 1) &&
                        (gui.Name.Substring(1).ToUpper() == tryName))
                    {
                        return true;
                    }
                }

                foreach (GUIControl control in gui.Controls)
                {
                    if ((control.Name == tryName) && (control != ignoreObject))
                    {
                        return true;
                    }
                }
            }

            foreach (InventoryItem item in this.RootInventoryItemFolder.AllItemsFlat)
            {
                if ((item.Name == tryName) && (item != ignoreObject))
                {
                    return true;
                }
            }

            foreach (Character character in this.RootCharacterFolder.AllItemsFlat)
            {
                if (character != ignoreObject)
                {
                    if (character.ScriptName == tryName)
                    {
                        return true;
                    }

                    if (character.ScriptName.StartsWith("c") &&
                        (character.ScriptName.Length > 1) &&
                        (character.ScriptName.Substring(1).ToUpper() == tryName))
                    {
                        return true;
                    }
                }
            }

            foreach (Dialog dialog in this.RootDialogFolder.AllItemsFlat)
            {
                if ((dialog.Name == tryName) && (dialog != ignoreObject))
                {
                    return true;
                }
            }

            if (IsNameUsedByAudioClip(tryName, this.RootAudioClipFolder, ignoreObject))
            {
                return true;
            }

            if (IsNameUsedByView(tryName, this.RootViewFolder, ignoreObject))
            {
                return true;
            }

            if ((_globalVariables[tryName] != null) &&
                (_globalVariables[tryName] != ignoreObject))
            {
                return true;
            }

            return false;
        }

Usage Example

Example #1
0
 private static void EnsureCharacterScriptNameIsUnique(Character character, Game game)
 {
     string scriptNameBase = character.ScriptName;
     int suffix = 0;
     while (game.IsScriptNameAlreadyUsed(character.ScriptName, character))
     {
         suffix++;
         character.ScriptName = scriptNameBase + suffix;
     }
 }
All Usage Examples Of AGS.Types.Game::IsScriptNameAlreadyUsed