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:

Looping with Unreal Engine

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 of the Size variable. Go to line 23 of PuzzleBlockGrid.cpp and change the value of the Size variable to four or five. Then, run the code again.

You should see the number of blocks on the screen increase, as shown in the following screenshot:

Looping with Unreal Engine

Setting the size to 14 creates many more blocks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.186