Hey, it is not recognizing my lives or HiddenWord

I followed the video, checked it, then tried making the variables public, that didn’t work
I’m still new to header files and would like to know what else I could possibly try
The variables work in the two functions we started with, but then it doesn’t recognize them when I move them to the new function

Code:
.h file

// Your declarations go below!
private:
FString HiddenWord{""};
int32 WordLength{0};
int32 Lives{0};

.cpp file

void InitGame()
{
//HiddenWord will be random at some point
HiddenWord = TEXT(“Cake”);
//corresponds to random word
WordLength = 4;
Lives = WordLength;
}

You wrote a non-member function. You need to define a member function

void UBullCowCartridge::InitGame()
{
    // Stuff
}
1 Like

DanM is correct, at least according to what you pasted.

Your HiddenWord seems to be correctly declared and initialized, so the problem is elsewhere.

The InitGame() is needs to be declared in the header file under “public”,

Header File Code
public:
	virtual void BeginPlay() override;
	virtual void OnInput(const FString& Input) override;
	void InitGame();

	// Your declarations go below!
	private:
	FString HiddenWord;
	int32 Lives; 

and then defined in the cpp file in the example DanM showed. It should work after that. Don’t forget to call it up in the BeginPlay function.

Thanks, I got it working, really appreciate the help

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

Privacy & Terms