Questions about these FOR and IF statements, and my debugger seeming to not work properly

I had a few questions during the video where we were taught the usage of if statements. First off, here’s the code:

FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
//increment the turn number
MyCurrentTry++;
//setup a return variable
FBullCowCount BullCowCount;
//loop thorugh all letters in the guess
int32 HiddenWordLength = MyHiddenWord.length();
for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++)
{
	//compare letters against the hidden word
	for (int32 GChar = 0; GChar < HiddenWordLength; GChar++)
	{
		//if they match then
		if (Guess[GChar] == MyHiddenWord[MHWChar])
		{
			//if they're in the same place
			if (MHWChar == GChar)
			{
				//Increment bulls 
				BullCowCount.Bulls++;
			
			}
			
			//else
			else 
			{
				//increment cows
				BullCowCount.Cows++;
			}
			
		}
	}
}

return BullCowCount;
}

The things I’m confused are at the top where “FString Guess” is included, and during the for loops. I assume that the “Guess” at the top is the same “Guess” at this getline command in main.cpp:

FText GetGuess()
{
int32 CurrentTry = BCGame.GetCurrentTry();

//get a guess from the player
FText Guess = "";
std::cout << "Try " << CurrentTry << ". Enter your guess: ";
std::getline(std::cin, Guess);
return Guess;
}

Correct me if my misunderstanding is incorrect. Like I had already said, I’m also confused with the FOR loop. How does the FOR loop know we are referring to the guess character with “GChar”" when we haven’t directly specified it. Same with the “MHWChar” looking at the my hidden word character. I don’t see anywhere where we assign these two value to their corresponding words. If someone could explain this to me I would appreciate it. If someone could explain the loop along with the IF statements I would be even more grateful. Here’s the link to the entire document for context.

Moving on to the second part. I found that I was unable to debug properly. It may be misuse but I was unable to add code to a watch list while debugging. I started the debugger, highlighted the line of code I wanted to put on the watch list, and right clicked. No watch list option was shown. Heres a picture showing the box that appears,

No watch list option shown

I am grateful for any response that can be offered. Once again thanks.

Never mind I think I figured out why the for loop works such as it does for the most part. I just didn’t realize that “SubmitGuess” had been set to a var before, and that guess acted as a var to hold that value. I was helped in seeing this with this video.

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

Privacy & Terms