✅ Troubles with looping
I'm building a text based adventure game to try and practice some syntaxes, as I'm a beginner. I'm stuck at this one part in the code where I need to repeat the loop only once if the user inputs an invalid input, however, despite me putting a valid input in there, it repeats it once, and after reinputting the same thing, it continues. I have one debug thing in there, please ignore that as I'll get rid of it whenever I figure this loop out. I'll post it after sending this, sending the entire code goes over the discord text limit.
46 Replies
might be better to do a text file actually, ill send it in a min
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/
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!That said, just paste the loop here
No need to send the whole entire project
alright, gimme a sec to get it then
sorry if it seems a bit sloppy, still trying to learn how to use it before optimizing it better
i've also tried a lot of different combinations for the while part, but it never worked
i've also tried simply using while instead of do-while, but it does the exact same thing i described
Odd, when I give the correct input, everything works as it should
really?
ill show you what it does on my end, give me a sec
Ah, giving incorrect input creates an infinite loop
this is what it's doing
i haven't tested that yet cause I'm trying to make it work on my end, and it's not for some reason, despite having the same code i put in here
Huh, you give a valid answer, and it just repeats the question?
yes, but only once
if i put a valid answer after it repeats, it works just fine
Seems like it would be something wrong with the outside code, then
Is this bit of code inside of another loop, maybe?
no. if you want, ill send the entire code. it's not that lengthy, as in the text based adventure game, i got stuck in the prologue section
Sure
$paste
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!
https://paste.mod.gg/uybtfujvcgxn/0
runOnce = true was a boolean i tried to use to fix this and abandoned it when it didn't work, just havent got rid of it yet
Right, I was able to reproduce the issue
alright
i tried looking over it again, i can't seem to find the issue lol
Ah
Well
You ask the question twice
And get input twice
i did?
Yes
yeah i must be blind cause i didnt see that at all
thank you, sorry for wasting your time lol
No problem
It's the smallest issues like this that are the hardest to notice lol
i swear i looked over it 5 times
lol true
Debugger helps a lot
Learning how to use even the basics like breakpoints is a gamechanger
so the loop does work, it's just the code that was screwed up
$debug
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Yeah
tbh
idk how to debug yet
Hence the link
It teaches you how
so i've been using Console.WriteLine("status is {status}") for my debugging lol
thank you for that
is there a resolved tag or something i can put on this post so others know its solved?
hey, quick question, how did you get the debugger to stay in the app? mine opens a seperate console tab
Not sure tbh
Been a while since I used VS
Oh, I remember the tag, $close
If you have no further questions, please use /close to mark the forum thread as answered
'Ere
does this
can't really use breakpoints bc of it
How come?
well, despite it telling me to press shift f5 to stop the debugging, it doesn't
unless im dumb
ok well it does, but the point is i have to switch back and forth between visual studio and the console tab app thing repeatedly instead of it all being in visual studio
How do I run my .NET console app in the integrated terminal instead...
Whenever you run or debug your .NET Console App, it opens a new windows terminal where the program is run. Isn't there a way to instead make that process headless and only show it in the integrated terminal or something? VSCode has a similar feature.
thank you, i was looking for that
and breakpoints magically decided to work now
did nothing different but it worked
It do be like that sometimes lol
$close
If you have no further questions, please use /close to mark the forum thread as answered