Using bool bPlayagain

Hey there,

I’ve had a pretty good understanding of the videos thus far, but the Boolean concept has thrown me for a loop. In this specific lesson, I don’t understand the meaning of: bool bPlayAgain = false
I understand a do while loop, but I’m not sure what the purpose of bPlayAgain is. We specify that bPlayAgain = AskToPlayAgain(); , why not write:

bool bAskToPlayAgain = false
do
{
PrintIntro();
PlayGame():
bAskToPlayAgain();
}
while (bAskToPlayAgain)

Is it because bAskToPlayAgain(); is not a function previously defined? Furthermore, why is it bool bPlayAgain=false and not =true? If the value returned from AskToPlayAgain is y, y=0, and 0=true, shouldn’t it be = true?

I apologize if this isn’t the most structured question, but I’d really like to get Boolean concepts nailed down before I continue. I appreciate any explanation you’re able to give me, thank you!

EDIT: Using the code created in this lesson, I changed bPlayAgain = false; to = true; and it functions exactly the same. I am quite confused. Please send help.

Hi @xstephencfox I’m definitely no expert but I’ll have a crack at trying to explain this one. The way Ben explains it, is you create an extra variable Boolean called bplayagain, it’s always best to initialize variables with a starting value, so in this case it doesn’t matter whether it is true or false. The reason is because an uninitialized variable is empty, and called a null value (someone else could chime in if I explained this right - coming from experience of unreal blueprints), and can cause havok with code later on if its not “set to a value”.
Anyways, continuing on, in this case we DO set the value in bPlayAgain to whatever AskToPlayAgain has as its return value, and then we use the bPlayAgain as our while loop question.

The way I get booleans is they ask simple yes/no questions.

Additionally, I did the challenge differently, as has a number of people. I just put the return output of AskToPlayAgain as my while loop:

image

The reason I did this is the value is already there, why create another variable when something is existing? Ben actually states this method is completely fine at the top of the video but he prefers the method stated.

I hope this helps you, if you need more help, GameDev.tv has a discord channel, I’m on regularly, and can help further, or reply to this topic

Regards,

Pete

@Wodger

I took an extended break from the course and have just now decided to jump back on, and noticed your reply. Thank you so much for getting back to me. I’m going to dive in a little deeper tonight and experiment with your method and see if it clears things up for me. Thanks so much!

Privacy & Terms