Errors in VS Code

I have been chasing my tail with this error.
My google needs a nap. Mr. Jeeves did not answer the door bell.

Here is BullCowCartridge.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include "BullCowCartridge.h"

#include "HiddenWordList.h"

void UBullCowCartridge::BeginPlay() 

{

    Super::BeginPlay();

    Isograms = GetValidWords(Words);

    SetupGame(); 

}

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

{

    if(bGameOver)

    {

        ClearScreen();

        SetupGame();

        return;

    }

    else // check player Guess

    {

        ProcessGuess(PlayerInput);

    }

}        

   

void UBullCowCartridge::SetupGame()//Function Declaration

{

    //Welcome Player

    PrintLine(TEXT("Welcome to Bullshit's Word Game!"));

    HiddenWord = Isograms[FMath::RandRange(0, Isograms.Num() - 1)]; //sets variable name and value

    Lives = HiddenWord.Len(); 

    bGameOver = false;

    PrintLine(TEXT("The secret word is %i letters\nYou have %i chances to answer"), HiddenWord.Len(), Lives); //deduct a life

    PrintLine(TEXT("Type your guess and press Enter"));

};

 

void UBullCowCartridge::EndGame()

{

    bGameOver = true;

    PrintLine(TEXT("\nPress enter to play again"));

}

void UBullCowCartridge::ProcessGuess(const FString& Guess)//pass variable in () to other functions using ()

{

    if (Guess == HiddenWord)

    {

        PrintLine (TEXT("\n\nCongratulations, You Win"));

        EndGame();

        return;   

    }  

    if (Guess.Len() != HiddenWord.Len())

    {

        PrintLine(TEXT("The Hidden Word is %i Characters Long, Try again"), HiddenWord.Len());

        return; //returns execution to where function was called. now lives wont be lost when a guess is the wrong number of characters

    }

    if (!IsIsogram(Guess))

    {

        PrintLine(TEXT("There are no repeated letters"));

        return;

    }       

        else

        {

            PrintLine (TEXT("You guessed wrong, you have %i chances left"), --Lives);

        }

    if (Lives <= 1)

    {

        ClearScreen();

        PrintLine(TEXT("You are out of guesses, You Lose"));

        PrintLine(TEXT("The secret word was %s"), *HiddenWord);

        EndGame();

        return;

    } 

    int32 Bulls;

    int32 Cows;

    GetBullCows(Guess, Cows, Bulls);

    PrintLine(TEXT("you have %i Bulls and %i Cows"), Bulls, Cows);

}   

bool UBullCowCartridge::IsIsogram(const FString& Word) const

{

    for (int32 Index = 0, Comparison = Index + 1; Comparison < Word.Len(); Comparison++)

    {

        for(int32 Comparison = Index + 1; Comparison < Word.Len(); Comparison++)

        {

            if (Word[Index] == Word[Comparison])

            {

                return false;

            }

        }

    }

    return true;

}

TArray<FString> UBullCowCartridge::GetValidWords(const TArray<FString>& WordList) const

{

    TArray<FString> ValidWords;

    for (FString Word : WordList) //range based for loop iterates through collection in array

    {

        if (Word.Len() >= 4 && Word.Len() <= 8)

        {

            if (IsIsogram(Word))

            {

            ValidWords.Emplace(Word);

            } 

        }

    } 

    return ValidWords;

}

void UBullCowCartridge::GetBullCows(const FString& Guess, int32& BullCount, int32& CowCount) const

{

    BullCount = 0;

    CowCount = 0;

    for (int32 GuessIndex = 0; GuessIndex < Guess.Len(); GuessIndex++)

    {

        if (Guess[GuessIndex] == HiddenWord[GuessIndex])

        {

            BullCount ++;

            continue;

        }

        

        for (int32 HiddenIndex =0; HiddenIndex < Guess.Len(); HiddenIndex++)

        {

            if (Guess[GuessIndex] == HiddenWord[HiddenIndex])

            {

                CowCount ++;

            }

            

        }

        

    }
}

And here is BullCowCartridge.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"

#include "Console/Cartridge.h"

#include "BullCowCartridge.generated.h"

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))

class BULLCOWGAME_API UBullCowCartridge : public UCartridge

{

    GENERATED_BODY()

    public:

    virtual void BeginPlay() override;

    virtual void OnInput(const FString& PlayerInput) override;

    void SetupGame();

    void EndGame();

    void ProcessGuess(const FString& Guess);

    bool IsIsogram(const FString& Word) const;

    TArray<FString> GetValidWords(const TArray<FString>& WordList) const;

    void GetBullCows(const FString& Guess, int32& BullCount, int32* CowCount) const;

    private:

    FString HiddenWord;

    int32 Lives;

    bool bGameOver;

    TArray<FString> Isograms;

};

The errors I get are

argument of type “int32” is incompatible with parameter of type “int32 *”

and

declaration is incompatible with “void UBullCowCartridge::GetBullCows(const FString &Guess, int32 &BullCount, int32 *CowCount) const” (declared at line 22 of “C:\UNREAL PROJECTS\TUTORIALS\BULLCOWGAME-STARTER-KIT\SOURCE\BULLCOWGAME\BullCowCartridge.h”)

The first error is in regards to GetBullCows(Guess, Cows, Bulls);

I notice that if I change the order of (Guess, Cows, and Bulls) the red squiggle is always under the last variable.

e.g. Guess, Bulls, Cows)

The second error is saying the GetBullCows function declaration isnt compatible with the header.

This makes me think the first error is due to the second error.

Thank you for any insight. This course is the first time I have touched anything remotely close to programming. I don’t have the prerequisite knowledge to figure this out. If the answer is something super easy- please talk to me like I am a five year old.

I do not know why my text shows up the way it did.
It is hard to read.
Second Question- how do I get code to format correctly when posting here?

for posting the code add ``` (3 tilde key on us keyboard before the one) before and after the code.

put the ``` on his own line after the last };

Thank you, I edited my response.

it appears that I cannot do that twice in the same post.

e.g.

introductory question

code example

secondary question

different code example

conclusion.

is that normal or do I need to do something different?

I think it is because the ``` tilde is not on his own line just before your end message

That fixed my posting issue. Thank you for the help.

you havre int& and the second is int * You need to change the last int32 parameter in the declaration

Good eye. That cleared up both errors.

Now my error is that GetBullCows is undefined.

int32 Bulls, Cows;
    GetBullCows(Guess, Cows, Bulls);

I figured it out. Thank you for all your help.

1 Like

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

Privacy & Terms