Hello am working with Unreal Engine 4 i was just wondering.
Can anyone please explain this statement for me? constbool bMatchIsOver = MyGameState && MyGameState->bMatchIsOver;
I dont get whats happening there.
MyGameState is a class and then a bool type.
The full code looks like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/** Accept or reject a player attempting to join the server.
* Fails login if you set the ErrorMessage to a non-empty string. */
void AShooterGameMode::PreLogin(const FString& Options,
const FString& Address,
const TSharedPtr<FUniqueNetId>& UniqueId,
FString& ErrorMessage)
{
Super::PreLogin(Options, Address, UniqueId, ErrorMessage);
AShooterGameState* const MyGameState = Cast<AShooterGameState>(GameState);
constbool bMatchIsOver = MyGameState && MyGameState->bMatchIsOver;
const FString EndGameError = TEXT("Match is over!");
ErrorMessage = bMatchIsOver ? *EndGameError : GameSession->ApproveLogin(Options);
}
nullptr is C++11. I still haven't updated so I'll explain it in C++03 terms:
We typically use the "NULL" design pattern when working with pointers. This means we'll set the value of a pointer to 0 when it doesn't point to anything. This helps us to identify the case where it doesn't point to anything an inhibits the access to inappropriate memory.
constbool bMatchIsOver = MyGameState && MyGameState->bMatchIsOver;
Does this:
1 2 3 4 5 6 7 8 9 10
#define NULL 0
bool MatchIsOver( AShooterGameState* const MyGameState )
{
if ( MyGameState != NULL ) // Only MyGameState actually points to something
{
if ( MyGameState->bMatchIsOver ) // Check the value of one of MyGameState's members
returntrue;
}
returnfalse;
}