Regarding the code in the header file

Hi,

So now i am able to write down the code and is almost half past coding the entire game. So my question is.

When i write a code in the header file viz :

Void ProcessGuess(Fstring Guess);

Gives me an error and find the screen as well during my compilation of the code. Please advise

Thanks


Hi Prateek,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Hope this helps :slight_smile:


See also;

Hi
You declared function ProcessGuess to accept only one argument:
void ProcessGuess(FString Guess);
But when you call it in your .cpp file (line 33) you pass two arguments instead of one:
ProcessGuess(Input,Lives);

Hi,

I think I see the problem, but can you copy all of the error log?

No one can see the rest of the messages that are running off the screen…

From your first picture you have
void ProcessGuess(FString Guess);

But from what we can see of the log, you have
ProcessGuess(Input, Lives);

So you are trying to pass in TWO parameters in a function that has been declared to accept ONE parameter.

Is that right ?

EDIT:
Oh, I see ARtemachka has the same idea.
They must have posted while I was typing.

Sure, it does, I will keep that in my mind for the future :slight_smile:

So here is the code and Since, I might not be able to present my code in a way that you would like me to, but still I’ll give it a best shot.

If we look the at the header file for Bulls and Cows that is BullCowCartridge.h, we have been using this file to make certain changes or declare the functions in our main cpp file. Right?

So, what I am trying to portray here is, when I am declaring the function that is void ProcessGuess(FString Guess); , it throws an error as it is not being accepted by the compiler. SO here is the bit of the code, for better understanding.

void UBullCowCartridge::ProcessGuess(FString Guess)
{

    if (Guess == HiddenWord)
    {
        PrintLine(TEXT(" You win !! "));
        EndGame();
        return;

    
    }

So, my concern, is when, I am running or compiling the code, it throws an error stating that /Users/prateekoswal/Downloads/BullCowGame-starter-kit-2 4.26/Source/BullCowGame/BullCowCartridge.h:19:7: note: ‘ProcessGuess’ declared here

 void ProcessGuess(FString Guess); // this statement is not getting accepted by the compiler

And that can be seen the screenshot as well which I pasted above. So, please if you understand, my point here, please try to help me out with this error.

Thanks for your response and understanding my statement. So yes, I did use this one as well . Check my snippet

if(bGameOver)
{
ClearScreen();
SetupGame();
}
else
{
ProcessGuess(Input,Lives); // here I declared it as well.

}

}

So, you are trying to say that I need to declare ProcessGuess(Input,Lives); in the header file as well?

Thanks for your response. Please find the code pasted and area of pain highlighted or commented

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{

if(bGameOver)
{
    ClearScreen();
    SetupGame();
}
else
{
    ProcessGuess(Input,Lives); // This is accepted and has been declared as well
    
}

}

void UBullCowCartridge::SetupGame()

{
// Welcoming the Player

HiddenWord = TEXT("cakes");

Lives = HiddenWord.Len();  

bGameOver = false ;

PrintLine(TEXT(“You have %i lives” ), Lives);

}

void UBullCowCartridge::EndGame()

{

bGameOver = true;

PrintLine(TEXT("\n Press Enter to Play again !! "));

}

void UBullCowCartridge::ProcessGuess(FString Guess) //// This one is the one I am talking about and is not being accepted by the complier even when I declared it in the header file.///

{

    if (Guess == HiddenWord)
    {
        PrintLine(TEXT(" You win !! "));
        EndGame();
        return;

    
    }

Hi again,

The copying of your code has messed up formatting.

If all of the code looks like this,
then it is very easily read.

Either way, near the start, look at your first ProcessGuess
It has TWO parameters.

I think your header file only has one.

Yes, that is correct. The processGuess is declared only once in the header file as stated in the video. Please have a look and let me know, if I need to add anything to it.

public:
virtual void BeginPlay() override;
virtual void OnInput(const FString& Input) override;

* *void SetupGame();  *
 * *void EndGame();*
* * void ProcessGuess(FString Guess);*

These bullet one, were declared by me in the header file. Is there anything else, I need to declare in the header file?

Sorry, it’s hard to understand what you are posting.
It is very unclear.

I think we have already given you a solution.
Is what we said true?

We haven’t seen your header file, so we are guessing by the output of the error log.

How many parameters are being passed ?

EDIT:
It isn’t about how many times the function has been declared in the header file.
It’s about how many PARAMETERS are being passed into that declared function.

thanks for replying. So for now 3 parameters are passed in the header file which are

void SetupGame();  
void EndGame();
void ProcessGuess(FString Guess);

This is what I saw in the video as well. What all apart from this, do I need to pass?

ok that’s your problem.

HEADER file:

void ProcessGuess(FString Guess);

.
.

CPP file:

ProcessGuess(Input,Lives);

.
.
You see?
The header has a function that has ONE parameter (called Guess).

But your cpp file has TWO (Input and Lives).
The cpp file is trying to pass in two parameters, but the header file said it should only have one.

that is right, I got your point. So, what do you suggest? Shall I pass another parameter like

void ProcessGuess(Input. Lives);

into the header file, or like how to I declare another parameter pertaining to ProcessGuess, in my header file to run the code without the errors?

We are not understanding each other.

Maybe someone else could help out.

I think you are referring to a “function” when you say “parameter”.

You declare a function, and that function can have a number of parameters (these are inside the brackets).

But the header and cpp files need to match.

I apologise for confusing parameters with the functions. So, I what I meant is , I passed 3 functions in the header file, that I stated above, right?

Now the CPP file is not accepting void ProcessGuess(Input. Lives);

as a function, because what I feel, I need to declare another “ProcessGuess” function in the header file, to void the error.

void ProcessGuess(FString Guess); // this function I already declared //

Now, do I need to declare any other function, in the header file with the name "ProcessGuess(parameters) " to avoid that error?

and by the way, you have been really helpful in the entire process. I am new to coding, that might be the reason of confusion, but I am trying to put forward my point, in best possible manner.

no, no.
Only declare the function once.

Re-watch the previous lectures.
If you declare a function to only accept ONE parameter,
but when it comes time to use that function you give it TWO,
then you will have an error.

EDIT:
Haha, yes, I am a newbie coder aswell.
Things like this will stick with you once they sink in.

I had issues with pointers and addresses, and had to re-watch the lectures too.

EDIT 2:
Anyway I need to go.
Best of luck.

Try modifying your code so only ONE parameter is passed into the ProcessGuess function. Something that is an FString.

Thanks for all the help i required. Well , ya, to be honest I need to re watch those videos :sweat_smile:

I’ll do what is required now and will make certain changes to the parameters passed in the ProcessGuess function as well. Hopefully it’ll work out this time

Thanks mate and cheers !!! :blush:

Privacy & Terms