Still not feeling warm & fuzzy :)

So one of the things I thought this part of the lecture might go into is actually fixing the error case that occurs here. Perhaps you do this in a later lecture. But to feel better about the code I fixed the issue of the array going out of range rather than assuming that the validity check caught it before the code could hit this error.

Assuming that this is not talked about in a later lecture, why not fix the array going out of bounds in this lesson? Seems like another good chance to demonstrate testing and validating your code. To me it felt like a bug was still being hidden even after the work done here.

Thanks, and liking the lesson thus far. Helping me to re-remember my C/C++ skills as I’ve mostly been coding in C# for years.

I had this exact same thought as well. Especially given the comments before the refactoring on the importance of actually fixing the code that had instead been patched on top of through the error enums. This just seems to rely on the patch job as well.

If anything I would think changing the int name from HiddenWordLength to WordLength, actually hides the bug better. And the comment is used to say that there is obviously an assumption being made that could result in a bug. Which seems to go against everything that has been taught so far.

Hey I actually also posted about this, could you explain exactly how you fixed the error? I can’t figure it out.

It’s been a VERY long time since I’ve looked at this, but what I’m guessing I did was to just make sure that both loops would never exceed the array lengths rather than assuming that the caller did the verification.
So here:


I replaced HiddenWordLength (well what he changed to WordLength which doesn’t fix the issue) to Guess.Length()

So this in his change there I changed from:
for (int32 GChar = 0; GChar < WordLength; GChar++) {

I changed to:
for (int32 GChar = 0; GChar < Guess.Length(); GChar++) {

Sorry, this is a year after your last post.
I’ve just started the course, and so far it’s been quite good. There’s been one or two times where I’ve questioned some of the decisions made in the tutorials, (one being putting the summary statistic inside the play game logic, in my opinion, whilst the game method is run, the game variables and logic are still “live”, and hence could change. Not reached the part where this is/ should be implemented yet, so hopefully Ben has changed his mind), and in this video, yep I don’t think lecture actually addressed the issue of the error arising. There’s still an index out of bounds exception, due to the WordLength being used.
I would say that your above solution is correct. Guess.Length() is the right thing to do. Also, if you don’t change it, I would possibly say that HiddenWordLength is better, it’s more specific… it lets you know EXACTLY which WordLength is used.
Also, as a bit more optimization, although small, I would be tempted to replace WordLength with the method GetHiddenWordLength(), it’s there, so might as well use it, and not define a new variable (unless there is a reason not to do it like this?).

// loop through all letters in the hidden word
	for (int32 HiddenWordChar = 0; HiddenWordChar < GetHiddenWordLength(); HiddenWordChar++)
	{
		// compare latters against the guess
		for (int32 GuessChar = 0; GuessChar < Guess.length(); GuessChar++) 
		{
			// if they match
			if (MyHiddenWord[HiddenWordChar] == Guess[GuessChar]) 
			{
				if (HiddenWordChar == GuessChar) 
				{ 
					BullCowCount.Bulls++; // increment bulls
				}
				else 
				{
					BullCowCount.Cows++; // increment cows
				}
			}
		}
	}

#unreal:ask Not sure why I’m getting these warnings. Thoughts??

Looks like you’re trying to use those variables before ever giving them values. Depending on where you are in the course, I believe those are set in the Reset() method, which is called by the constructor. Could you share the contents of all the files?

Privacy & Terms