C
C#2mo ago
killa.rei

✅ Selection using spectre.console

``cs using Spectre.Console; using System.Threading.Channels; void choiceMenu() { var choice = AnsiConsole.Prompt( new SelectionPrompt<string>() .AddChoices(new[] { "1| Reboot Audio Systems" , "2| Reboot Camera Systems" , "3| Reboot Ventilation System" , "4| Reboot All Systems" })); } Console.Beep(1500, 800); if ( = ); Console.Beep(1200, 800); Console.Write("0");
I want to make it so that when option 1 is selected (audio systems) it runs console.beep and prints "0".

using choiceMenu in the if statement:
I want to make it so that when option 1 is selected (audio systems) it runs console.beep and prints "0".

using choiceMenu in the if statement:
cs if (choiceMenu = 1 ; Console.beep(1000, 800); ``` only gives me a method group error. I dont know how to go about this, please help
No description
15 Replies
Buddy
Buddy2mo ago
$paste
MODiX
MODiX2mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
viceroypenguin
viceroypenguin2mo ago
in the future, please do not include a picture of yourself (i assume?). it is not helpful to the helping process
using Spectre.Console;

const string Prompt1 = "1. Reboot Audio Systems";
const string Prompt2 = "2. Reboot Camera Systems";
const string Prompt3 = "3. Reboot Ventilation Systems";
const string Prompt4 = "4. Reboot All Systems";

var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Please select an [green]action[/].")
.AddChoices(
[
Prompt1,
Prompt2,
Prompt3,
Prompt4,
]
);

if (choice is Prompt1 or Prompt4)
{
Console.Beep(1200, 800);
Console.Write("0");
}
using Spectre.Console;

const string Prompt1 = "1. Reboot Audio Systems";
const string Prompt2 = "2. Reboot Camera Systems";
const string Prompt3 = "3. Reboot Ventilation Systems";
const string Prompt4 = "4. Reboot All Systems";

var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Please select an [green]action[/].")
.AddChoices(
[
Prompt1,
Prompt2,
Prompt3,
Prompt4,
]
);

if (choice is Prompt1 or Prompt4)
{
Console.Beep(1200, 800);
Console.Write("0");
}
killa.rei
killa.reiOP2mo ago
not me, thought it was a nice addition
viceroypenguin
viceroypenguin2mo ago
it is not
killa.rei
killa.reiOP2mo ago
thank you this is much more organised hello sir I have 1 more follow up question I wanna make this selection thing a method so I can pull it up faster, but when I do it, the choice in the if statement doesnt work anymore because its now indented into the method
viceroypenguin
viceroypenguin2mo ago
@killa.rei strongly suggest you learn how to actually write functions. the code you have shared so far indicate that you do not.
int DoSomething()
{
return 5;
}

var val = DoSomething();
int DoSomething()
{
return 5;
}

var val = DoSomething();
killa.rei
killa.reiOP2mo ago
No description
Angius
Angius2mo ago
$scopes
MODiX
MODiX2mo ago
scope A {
thing a;
scope B {
thing b;
}
}
scope A {
thing a;
scope B {
thing b;
}
}
thing a is available in scope A and scope B thing b is available only in scope B
Angius
Angius2mo ago
choice variable exists within the choiceMenu() method and only there You probably want to return the choice from the method And use that
ero
ero2mo ago
There is no method body in that screenshot
Angius
Angius2mo ago
Ah, right, the semicolon
killa.rei
killa.reiOP2mo ago
so how would i call it in an if statement? acc lemme search up
maxmahem
maxmahem2mo ago
lol! my bad

Did you find this page helpful?