SetVariable() public static method

public static SetVariable ( string variable, string value ) : void
variable string
value string
return void
コード例 #1
0
        private void EndREADFILE()
        {
            // TODO _InWRITEFILE could be handled like this, so no need for multiple writes per writefile
            if (File.Exists(_InREADFILE))
            {
                string[] Lines = FileUtils.FileReadAllLines(_InREADFILE, RMEncoding.Ansi);

                int LoopMax = Math.Min(Lines.Length, _InREADFILELines.Count);
                for (int i = 0; i < LoopMax; i++)
                {
                    RTVariables.SetVariable(_InREADFILELines[i], RTVariables.TranslateVariables(Lines[i]));
                }
            }
        }
コード例 #2
0
        // TODOX Abstract some of this out to RTChoiceOption so you can easily retrieve a list of visible options
        private void EndCHOICE()
        {
            /* @CHOICE
             *  <A choice>
             *  <another choice>
             *  <ect..When a @ is found in the beginning of a choice it quits>
             *  This gives the user a choice using a lightbar.
             *  The responce is put into varible RESPONCE.  This may also be spelled RESPONSE.
             *  To set which choice the cursor starts on, put that number into `V01.
             ** EXAMPLE OF @CHOICE COMMAND **
             ** @DO `V01 IS 1 ;which choice should be highlighted when they start
             ** (now the actual choice command)
             ** @CHOICE
             ** Yes   <- Defaults to this, since it's 1
             ** No
             ** I don't know
             ** Who cares
             ** @IF RESPONCE IS 3 THEN DO
             **   @BEGIN
             **   @DO `P01 IS RESPONCE
             **   @SHOW
             **
             ** You chose `P01!, silly boy!
             **
             **   @END
             ** The choice command is more useful now; you can now define *IF* type statements
             ** so a certain choice will only be there if a conditional statement is met.
             ** For instance:
             ** @CHOICE
             ** Yes
             ** No
             ** =`p20 500 Hey, I have 500 exactly!
             ** !`p20 500 Hey, I have anything BUT 500 exactly!
             ** >`p20 500 Hey, I have MORE than 500!
             ** <`p20 100 Hey, I have LESS than 100!
             ** >`p20 100 <`p20 500 I have more then 100 and less than 500!
             ** Also:  You can check the status of individual bits in a `T player byte.  The
             ** bit is true or false, like this:
             +`t12 1 Hey! Byte 12's bit 1 is TRUE! (which is 1)
             ** -`t12 3 Hey! Byte 12's bit 3 is FALSE! (which is 0)
             **
             ** The = > and < commands can be stacked as needed.  In the above example, if
             ** `p20 was 600, only options 1, 2, 4, and 5 would be available, and RESPONSE
             ** would be set to the correct option if one of those were selected.  For
             ** example, if `p20 was 600 and the user hit the selection:
             ** "Hey, I have more than 500", RESPONSE would be set to 5. */


            // Determine which options are Visible and assign VisibleIndex
            int VisibleCount      = 0;
            int LastVisibleLength = 0;

            char[] IfChars = { '=', '!', '>', '<', '+', '-' };
            for (int i = 0; i < _InCHOICEOptions.Count; i++)
            {
                bool MakeVisible = true;

                // Parse out the IF statements
                while (Array.IndexOf(IfChars, _InCHOICEOptions[i].Text[0]) != -1)
                {
                    // Extract operator
                    char Operator = _InCHOICEOptions[i].Text[0];
                    _InCHOICEOptions[i].Text = _InCHOICEOptions[i].Text.Substring(1);

                    // Extract variable and translate
                    string Variable = _InCHOICEOptions[i].Text.Split(' ')[0];
                    _InCHOICEOptions[i].Text = _InCHOICEOptions[i].Text.Substring(Variable.Length + 1);
                    Variable = RTVariables.TranslateVariables(Variable);

                    // Extract value
                    string Value = _InCHOICEOptions[i].Text.Split(' ')[0];
                    _InCHOICEOptions[i].Text = _InCHOICEOptions[i].Text.Substring(Value.Length + 1);

                    // Determine result of if
                    switch (Operator)
                    {
                    case '=':
                        MakeVisible = MakeVisible && (Convert.ToInt32(Variable) == Convert.ToInt32(Value));
                        break;

                    case '!':
                        MakeVisible = MakeVisible && (Convert.ToInt32(Variable) != Convert.ToInt32(Value));
                        break;

                    case '>':
                        MakeVisible = MakeVisible && (Convert.ToInt32(Variable) > Convert.ToInt32(Value));
                        break;

                    case '<':
                        MakeVisible = MakeVisible && (Convert.ToInt32(Variable) < Convert.ToInt32(Value));
                        break;

                    case '+':
                        MakeVisible = MakeVisible && ((Convert.ToInt32(Variable) & (1 << Convert.ToInt32(Value))) != 0);
                        break;

                    case '-':
                        MakeVisible = MakeVisible && ((Convert.ToInt32(Variable) & (1 << Convert.ToInt32(Value))) == 0);
                        break;
                    }
                }

                // Determine if option is visible
                if (MakeVisible)
                {
                    VisibleCount                    += 1;
                    LastVisibleLength                = Door.StripSeth(_InCHOICEOptions[i].Text).Length;
                    _InCHOICEOptions[i].Visible      = true;
                    _InCHOICEOptions[i].VisibleIndex = VisibleCount;
                }
                else
                {
                    _InCHOICEOptions[i].Visible = false;
                }
            }

            // Ensure `V01 specified a valid/visible selection
            int SelectedIndex = Convert.ToInt32(RTVariables.TranslateVariables("`V01"));

            if ((SelectedIndex < 1) || (SelectedIndex > _InCHOICEOptions.Count))
            {
                SelectedIndex = 1;
            }
            while (!_InCHOICEOptions[SelectedIndex - 1].Visible)
            {
                SelectedIndex += 1;
            }

            // Determine how many spaces to indent by (all lines should be indented same as first line)
            string Spaces = "\r\n" + new string(' ', Crt.WhereX() - 1);

            // Output options
            Door.CursorSave();
            Door.TextAttr(15);
            for (int i = 0; i < _InCHOICEOptions.Count; i++)
            {
                if (_InCHOICEOptions[i].Visible)
                {
                    if (_InCHOICEOptions[i].VisibleIndex > 1)
                    {
                        Door.Write(Spaces);
                    }
                    if (i == (SelectedIndex - 1))
                    {
                        Door.TextBackground(Crt.Blue);
                    }
                    Door.Write(RTVariables.TranslateVariables(_InCHOICEOptions[i].Text));
                    if (i == (SelectedIndex - 1))
                    {
                        Door.TextBackground(Crt.Black);
                    }
                }
            }

            // Get response
            char?Ch = null;

            while (Ch != '\r')
            {
                int OldSelectedIndex = SelectedIndex;

                Ch = Door.ReadKey();
                switch (Ch)
                {
                case Door.ExtendedKeys.LeftArrow:
                case Door.ExtendedKeys.UpArrow:
                case '8':
                case '4':
                    while (true)
                    {
                        // Go to previous item
                        SelectedIndex -= 1;

                        // Wrap to bottom if we were at the top item
                        if (SelectedIndex < 1)
                        {
                            SelectedIndex = _InCHOICEOptions.Count;
                        }

                        // Check if new selected item is visible (and break if so)
                        if (_InCHOICEOptions[SelectedIndex - 1].Visible)
                        {
                            break;
                        }
                    }
                    break;

                case Door.ExtendedKeys.RightArrow:
                case Door.ExtendedKeys.DownArrow:
                case '6':
                case '2':
                    while (true)
                    {
                        // Go to previous item
                        SelectedIndex += 1;

                        // Wrap to bottom if we were at the top item
                        if (SelectedIndex > _InCHOICEOptions.Count)
                        {
                            SelectedIndex = 1;
                        }

                        // Check if new selected item is visible (and break if so)
                        if (_InCHOICEOptions[SelectedIndex - 1].Visible)
                        {
                            break;
                        }
                    }
                    break;
                }

                if (OldSelectedIndex != SelectedIndex)
                {
                    // Store new selection
                    RTVariables.SetVariable("`V01", SelectedIndex.ToString());

                    // Redraw old selection without blue highlight
                    Door.CursorRestore();
                    if (_InCHOICEOptions[OldSelectedIndex - 1].VisibleIndex > 1)
                    {
                        Door.CursorDown(_InCHOICEOptions[OldSelectedIndex - 1].VisibleIndex - 1);
                    }
                    Door.Write(RTVariables.TranslateVariables(_InCHOICEOptions[OldSelectedIndex - 1].Text));

                    // Draw new selection with blue highlight
                    Door.CursorRestore();
                    if (_InCHOICEOptions[SelectedIndex - 1].VisibleIndex > 1)
                    {
                        Door.CursorDown(_InCHOICEOptions[SelectedIndex - 1].VisibleIndex - 1);
                    }
                    Door.TextBackground(Crt.Blue);
                    Door.Write(RTVariables.TranslateVariables(_InCHOICEOptions[SelectedIndex - 1].Text));
                    Door.TextBackground(Crt.Black);
                }
            }

            // Move cursor below choice statement
            Door.CursorRestore();
            Door.CursorDown(VisibleCount - 1);
            Door.CursorRight(LastVisibleLength);

            // Update global variable responses
            RTGlobal.RESPONSE = SelectedIndex.ToString();
        }