Book Image

Learning C++ by creating games with UE4

By : William Sherif
Book Image

Learning C++ by creating games with UE4

By: William Sherif

Overview of this book

Table of Contents (19 chapters)
Learning C++ by Creating Games with UE4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Variables and Memory
Index

Looping with Unreal Engine


In your code editor, open your Unreal Puzzle project from Chapter 3, If, Else, and Switch.

There are several ways to open your Unreal project. The simplest way is probably to navigate to the Unreal Projects folder (which is present in your user's Documents folder on Windows by default) and double-click on the .sln file in Windows Explorer, as shown in the following screenshot:

On Windows, open the .sln file to edit the project code

Now, open the PuzzleBlockGrid.cpp file. Inside this file, scroll down to the section that begins with the following statement:

void APuzzleBlockGrid::BeginPlay()

Notice that there is a for loop here to spawn the initial nine blocks, as shown in the following code:

// Loop to spawn each block
for( int32 BlockIndex=0; BlockIndex < NumBlocks; BlockIndex++ )
{
  // ...
}

Since NumBlocks (which is used to determine when to stop the loop) gets computed as Size*Size, we can easily change the number of blocks that get spawned by altering the value...