C# while loop with user input

Hi there,
I work on code with C# and I don’t find to understand behavior in one simple situation.
I want user to confirm moment when while loop should stop or be continued by entering yes or no. This part of the code (part2) works without part1, but does not work with part1 of the while loop. If user enters yes, he does not receive another prompt to select additional 2 objects, but being contently asked if he wants to continue. Given no as input loop exits without problem. Any explanation on what I am missing?
Code:

while(true)
{
//PART1
var go = new GetObject();
go.GetMultiple(2, 0);

            Curve curveA = go.Object(0).Curve(), curveB = go.Object(1).Curve();

            //Other code
            // ...
            //
            //PART2
            var response = new GetString();
            response.SetCommandPrompt("Do you want to continue: y/n");
            response.Get();

            if (response.ToString() == "n")
                break;
            else if(response.ToString() == "y")
                continue;
        }

Hi,
It should be because the objects you selected in part 1 are still in the ‘Selected’ state. So go.GetMultiple(2,0) is satisfied without further input from you. There are two ways to about this:

  1. The long way around - manually unselect all objects
///Rest of your code

if (response.ToString() == "n")
    break;
else if(response.ToString() == "y")
{
    var doc = RhinoDoc.ActiveDoc; 
    doc.Objects.UnselectAll();
    doc.Views.Redraw();
    continue;
}

OR

  1. The ‘correct’ way - define selection preferences in the settings of Get object
while (true)
{
    // PART1
    var go = new GetObject();
    go.DisablePreSelect(); ///Add this line
    go.GetMultiple(2, 0);

////Rest of your code

}
1 Like

Second works like charm.

Thank you! @Bovas_Benny