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:
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...