Hey Adam, I will try to straighten out some confusion. I’ve been in the same place as you, and the biggest problem is that Ben kind of treats all code concepts equally. In truth, you’re learning a couple code concepts without being able to tell the difference.
I will try to explain.
-
There are code concepts that are almost UNIVERSAL. These are things like IF Statements, WHILE loops, Addition, Subtraction, bools, ints, strings etc.
-
Then there are code concepts that are Universal to OBJECT-ORIENTED programming. These are things like classes, instances and inheritance.
-
Then there are coding concepts specific to C++. This generally is the syntax. For example this is how you write “Hello World” in C++
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
and here is how you write “Hello World” in Python:
Print("Hello World")
Both share the same universal concept of printing a string, they function the same way, but the syntax is different.
- Finally there are concepts that ONLY apply to Unreal Engine 4 C++. These are things like FStrings and later on in the video you will be dealing with a lot of UE4 specific code, that wouldn’t work outside of UE4.
So the challenge for you is figuring out which 4 categories does a specific line of code sit in. Honestly, you’re doing the right thing. I learn a lot more by doing 1-2 videos a day and letting the information sink in, if I rush through 10 videos I forget a lot.
I will try and give you a head start by explaining the line your stuck on.
FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess);
So lets break it down.
FBullCowCount BullCowCount
FBullCowCount is a struct, containing 2 integers (Bulls and Cows). If we only needed 1 integer instead of two we could simply write
int BullCowCount
So in psuedo code we’re just saying “I’ve created a new variable call BullCowCount and It’s a struct containing 2 integers named Bulls and Cows.” However these names are arbitary. We could have just written.
struct myStruct {int x, int y};
myStruct newStruct;
newStruct.x = 1;
newStruct.y = 2;
We just set the x and y values to 1 and 2 for the variable newStruct.
Okay so we know that the left hand side is just declaring a new variable of type FBullCowCount which is a struct! Remember from earlier a struct falls into our 1) category of universal coding concepts.
So what does this mean?
FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
Well SubmitValidGuess is a method that is inside the class of FBullCowGame. However early in our code we made an INSTANCE of this class called BCGame. This is an example of 2) Object Oriented Programming. We don’t won’t deal with the literal class which is more like a blueprint. We want to deal with an OBJECT of the blueprint, which is an instance.
Okay so we have our instance of a class and we’re asking it to call a method called SubmitValidGuess. Well if you look at the method in the original file (FBullCowGame) You will see that it increments BullCowCount.Bulls and BullCowCount.Cows based on some conditions.
So to summarize. We declared a new struct called BullCowCount, and we made it’s value equal to the value returned by a method called SubmitGuess. The value that SubmitGuess returns is based on some conditions of the input. In this case the input is a string called Guess.
Now I’m a bit ahead of you in the tutorial so I will give you I will give you some tips for the upcoming sections.
An important thing to know about UE4 C++ is that Unreal Engine “coddles you”. It basically asks you to build on top of it’s existing code, rather than creating new code from scratch.
More specifically, it asks you to use its existing CLASSES. “We’ve made some classes for you to use, so please only create children of these classes”. Now UE4 comes with about 1000 of these “in built classes” but the one you use the most is a class called AActor. So UE4 asks you "If you make any object that can be placed in the world, like a light, or a door, or a sound, please make it a child of an AActor.
Why do we do this? Well the prebuilt AActor class already has hundreds of functions in it that are EXTREMELY useful. So we can make a new door class, called ADoorClass. ADoorClass INHERITS from AActor. Which means it has all the same methods AActor has.
So we can say ADoorClass.SetActorTransform(0,0,0) and just with a simple function we can set the doors location to 0,0,0. UE4 has already written the code for us. However if ADoorActor was not a child of AActor we would not have access to any of it’s cool functions.
So just be aware then you move over to UE4 you’re not swimming in an endless of ocean of C++ freedom (which is terrifying!) but you’re coding in the structured world of the UE4 framework.
So to summarize my long post. Even if you don’t understand the code, just try to think to yourself “Is this a universal concept, an object oriented concept, a C++ concept or just a UE4 concept?”