Slightly different way to get the same behavior BC Game

I believe I’ve gotten the same behavior by using a while loop instead of an if statement. Is there anything wrong with this approach? Or is one or the other preferable for any reason?

Here is my OnInput function:

It looks fine to me, since the returns are there. otherwise it probably wouldn’t work.

Just curious, what’s SetupGame() doing at the bottom there? Due to the While loop, it will only be called if bGameOver is true; which (assuming the rest of your code isn’t different like this) means that it’s completely unnecessary, since that should cause an extra game window to appear after the game ends, and that doesn’t make much sense to me.

I can confirm that if the returns aren’t there it will definitely not work. Figured that out after crashing Unreal a few times…

I had my SetupGame() function set up a bit differently in prep for a WinScreen() and LoseScreen() function to replace EndGame();

Thanks for taking a look for me!

1 Like

Yes, the while loop has no effect so using while to mean if is misleading.

This function is called when the user presses enter. With a while loop the user wouldn’t be able to enter anything else until the while loop ends. So if you were to remove the returns this would loop forever if the guess is invalid.

1 Like

Thanks @DanM ! That definitely helps me understand the difference in approaches and where one might prefer a while loop to an if and vice versa.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms