a quick c++ snippet test

Home base.

This is the first c++ display test for the blog.

The C++ embedded in this block is throwaway code to test the syntax highlighting. Because this blog is intended not only to display formatted text allowing me to tell a story, it must also clearly display code snippets for either future me or a reader.

So, to display a header file:

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "BaseBlueprintActor.generated.h"

UPROPERTY(EditAnywhere)
UStaticMeshComponent* Box;

UPROPERTY(EditAnywhere)
UStaticMeshComponent* Sphere;

UFUNCTION()
void bool BoxIsValid();

UFUNCTION()
void ToggleSphere();

After which I would explain something specific, for example, why line 12 is incorrect. As explained here:

UFUNCTION()
void bool BoxIsValid(); //incorrect deceleration. Void cannot have a return type.

The deceleration is incorrect. It is either a void function or a static bool and because we do want the bool returned whether the box is valid or not, the correct formatting would be:

UFUNCTION()
static bool BoxIsValid(); //static bool will return a bool we can use to do stuff...or not do stuff.

At this point, we can move onto the .cpp file. I will override the default BeginPlay function to run our corrected BoxIsValid() function to start the flow.

#include "BaseBlueprintActor.h"

void ABaseBlueprintActor::BeginPlay()

{
   if (ABaseBlueprintActor::BoxIsValid)//using the returned bool to control the flow of this statement. 

{
//only toggle the sphere if BoxIsValid returns true.
ABaseBlueprintActor::ToggleSphere;
}
else
{
//Do Nothing
}
}

And there we have it! Not only have I tested the syntax highlighting for C++, but the first blog post has also been posted.
Here’s to a bright future of blogging.

Site Footer