Recently i have come across a problem in my “BullCowCartrage.cpp” file, an error stating “member function ‘void UBullCowCartridge::InitGame()’ may not be declared outside of it’s class”
my code looks like the following:
void UBullCowCartridge::InitGame();
{
// welcoming the player
PrintLine(TEXT("Welcome to Ezra's bullcow game!"));
PrintLine(TEXT("guess the %i letter word."), HiddenWord.Len());
PrintLine(TEXT("type in your guess and press enter to"));
PrintLine(TEXT("continue...")); // prompt player for guess
HiddenWord = TEXT("cakes");
Lives = 5;
bGameOver = false;
}
does anyone actually know what the problem is here?
when i do that it gives me another error that states “expected a ‘;’” which leaves me with the same problem as i can not remove the ‘;’. else the function will not work at all
void UBullCowCartridge::InitGame()
{
// welcoming the player
PrintLine(TEXT("Welcome to Ezra's bullcow game!"));
PrintLine(TEXT("guess the %i letter word."), HiddenWord.Len());
PrintLine(TEXT("type in your guess and press enter to"));
PrintLine(TEXT("continue...")); // prompt player for guess
HiddenWord = TEXT("cakes");
Lives = 5;
bGameOver = false;
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
InitGame();
PrintLine(TEXT("the Hidden Word is: %s"), *HiddenWord); // debug messages
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
// if the game is over than do ClearScreen() and Initgame() the game
// else checking PlayerGuess
if (bGameOver)
{
ClearScreen();
InitGame();
}
else
{
if (Input == HiddenWord)
{
PrintLine(TEXT("You have won!"));
bGameOver = true;
}
else
{
if (Input.Len() != HiddenWord.Len())
{
PrintLine(TEXT("oooo, that's too many or too little words dumbass, try again"));
}
PrintLine(TEXT("You're trash kid, go home!"));
bGameOver = true;
}
// Check if isogram
// prompt to guess again
// Check right number of characters
// prompt to guess again
// Remove Life
// Check if Lives > 0
// If yes GuessAgain
// show lives left
// if no show gameover and HiddenWord?
// prompt to play again, press enter to play again?
// check user input
// PlayAgain or Quit
}
void UBullCowCartridge::InitGame()
{
// welcoming the player
PrintLine(TEXT("Welcome to Ezra's bullcow game!"));
PrintLine(TEXT("guess the %i letter word."), HiddenWord.Len());
PrintLine(TEXT("type in your guess and press enter to"));
PrintLine(TEXT("continue...")); // prompt player for guess
HiddenWord = TEXT("cakes");
Lives = 5;
bGameOver = false;
That says you tried to create a function within another function. Fixing indentation you have the following.
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
// if the game is over than do ClearScreen() and Initgame() the game
// else checking PlayerGuess
if (bGameOver)
{
ClearScreen();
InitGame();
}
else
{
if (Input == HiddenWord)
{
PrintLine(TEXT("You have won!"));
bGameOver = true;
}
else
{
if (Input.Len() != HiddenWord.Len())
{
PrintLine(TEXT("oooo, that's too many or too little words dumbass, try again"));
}
PrintLine(TEXT("You're trash kid, go home!"));
bGameOver = true;
}
// Check if isogram
// prompt to guess again
// Check right number of characters
// prompt to guess again
// Remove Life
// Check if Lives > 0
// If yes GuessAgain
// show lives left
// if no show gameover and HiddenWord?
// prompt to play again, press enter to play again?
// check user input
// PlayAgain or Quit
}
void UBullCowCartridge::InitGame()
{
// welcoming the player
PrintLine(TEXT("Welcome to Ezra's bullcow game!"));
PrintLine(TEXT("guess the %i letter word."), HiddenWord.Len());
PrintLine(TEXT("type in your guess and press enter to"));
PrintLine(TEXT("continue...")); // prompt player for guess
HiddenWord = TEXT("cakes");
Lives = 5;
bGameOver = false;
}
// ???
Which is doing this
void Foo()
{
void Bar() // defining a function within a function
{
}
}