Example #1
0
        public float GetFloat(string name)
        {
            idInternalCvar intern = FindInternal(name);

            if (intern != null)
            {
                return(intern.ToFloat());
            }

            return(0);
        }
Example #2
0
        private void Cmd_Toggle(object sender, CommandEventArgs e)
        {
            int argCount = e.Args.Length;

            if (argCount < 2)
            {
                idConsole.WriteLine("usage:");
                idConsole.WriteLine("    toggle <variable> - toggles between 0 and 1");
                idConsole.WriteLine("    toggle <variable> <value> - toggles between 0 and <value>");
                idConsole.WriteLine("    toggle <variable [string 1] [string 2]...[string n] - cycles through all strings");
            }
            else
            {
                idInternalCvar cvar = idE.CvarSystem.FindInternal(e.Args.Get(1));

                if (cvar == null)
                {
                    idConsole.WriteLine("toggle: cvar \"{0}\" not found", e.Args.Get(1));
                }
                else if (argCount > 3)
                {
                    // cycle through multiple values
                    string text = cvar.ToString();
                    int    i    = 0;


                    for (i = 2; i < argCount; i++)
                    {
                        if (StringComparer.CurrentCultureIgnoreCase.Compare(text, e.Args.Get(i)) == 0)
                        {
                            i++;
                            break;
                        }
                    }

                    if (i >= argCount)
                    {
                        i = 2;
                    }

                    idConsole.WriteLine("set {0} = {1}", e.Args.Get(1), e.Args.Get(i));
                    cvar.Set(e.Args.Get(i), false, false);
                }
                else
                {
                    // toggle between 0 and 1
                    float current = cvar.ToFloat();
                    float set     = 0;

                    if (e.Args.Length == 3)
                    {
                        float.TryParse(e.Args.Get(2), out set);
                    }
                    else
                    {
                        set = 1.0f;
                    }

                    if (current == 0.0f)
                    {
                        current = set;
                    }
                    else
                    {
                        current = 0.0f;
                    }

                    idConsole.WriteLine("set {0} = {1}", e.Args.Get(1), current);
                    cvar.Set(current.ToString(), false, false);
                }
            }
        }