Time for action – Using structs
Going back to our basket of kittens example, what if there were other things in the basket besides kittens? How would we represent them?
Let's create a struct at the top of our AwesomeActor class and put a few things in it.
struct Basket { var string BasketColor; var int NumberOfKittens, BallsOfString; var float BasketSize; };
Now we have two types of items in the basket as well as some variables to describe the basket itself.
Now we need a variable of that struct so we can use it:
var Basket MyBasket;
Now we can change the values in our
PostBeginPlay
function.function PostBeginPlay() { MyBasket.NumberOfKittens = 4; MyBasket.BasketColor = "Yellow"; MyBasket.BasketSize = 12.0; MyBasket.BallsOfString = 2;}
That seems easy enough to handle. Let's try something a bit more complex.
I heard you like structs, so we'll Inception-ize it by adding a struct inside a struct.
struct SmallBox { var int Chocolates; var int Cookies; };
Now let's...