❔ stuck on a code in a console game
so basically the compiler was STUCK on a code
and I got stuck on this so I thought it'd be interesting if I came here
some people say the Development Environment is messed up, or try using a new IDE
I made this boring console game cause I was bored btw (I use unity most of the time but I got bored this time so yes.)
19 Replies
Program01.cs:
Program02.cs:
what do y'all think?
you mean stuck in your infinite while loop?
yes.
stuck on this:
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
well it's "stuck" because of this:
while (true)
what am I supposed to change it to?
well a while loop carries on looping until the condition inside the parentheses is false, so if you put "true" in there it will loop infinitely (unless there's a return or break statement etc inside the loop)
so what you're supposed to do is change it to a condition that at some point becomes false, which depends on what the purpose of the loop is
well look at the while loop.
Cast--;
makes me think you want it to carry on until they run out of spells casts? But then you have that loop inside the if statement where they have 0 casts left alreadyyes i'll change that
ik
I'm just focusing on the while loop
yeah which is why I wanted you to explain it
itself
ok so what do you want the while loop to do?
well M is gonna exit out of the loop.
and if they press other than K/M it will continue looping.
ok so you need to change it to
while (pressed key != K or M)
omg-
or keep it as
while (true)
and inside the loop check what key's been pressed, and if it's K or M, break
out of the loopblud,
K is gonna terminate the process
while M is gonna execute Program02.
no errors / warnings in any of the files.
why would there be?
I'm not called blud either
so you'd check for what key's been pressed in your loop, if it's K, return/terminate whatever, if it's M call Program02 (then what?), otherwise do whatever
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.