My BullCow Wrapup (Extra features and followup question)

Here is my latest version of the BullCow game but I may add more features when I have spare time. I thought it was a little harsh that the player would lose points because they guessed something that was not an isogram or had the incorrect number of letters. I decided to fix that by adding a new function called IsValidGuess. It returns a boolean and an out parameter called problems. This gives us an FString that tells us why the player’s input is not valid. I wanted to concatenate it because I think it looks better when the bullet points are added after it says “Sorry, that was not a valid guess.”

However I am having a small problem where %i is not being replaced by HiddenWord.Len() when being passed into the FString function. Down below you’ll see that it reads “* Your guess has to be %i characters long.” I’m guessing that you have to do something special with FString since you did not override the method like PrintLine(). I tried passing the string into FString::printf() but the number that replaced %i was a large number in the hundred thousand range. I decided to not dwell on the problem right now. Hopefully as I continue to follow this course, and learn more about C++, I’ll be able to solve the problem. But if you know the answer I’d be grateful if you told me how to solve it.

My Code:

BullCow changes:

Can you try replacing the %i with %s and see what happens?

This was already how the game was coded. So a little confused about this.


Your code is incorrect. The constructor you are calling does not do any formatting, you’re just giving it space to hold HiddenWord.Len() extra characters

https://docs.unrealengine.com/en-US/API/Runtime/Core/Containers/FString/__ctor/6/index.html

FString::Printf was the correct thing to use. You don’t need "" either

FString Problems;
// code...
Problems += FString::Printf(TEXT("Some text %i", HiddenWord.Len());

Should work.

1 Like

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

Privacy & Terms