if (role == ROLE_Authority)



void AThirdPersonMPCharacter::OnHealthUpdate()
{
    //Client-specific functionality
    if (IsLocallyControlled())
    {
        FString healthMessage = FString::Printf(TEXT("You now have %f health remaining."), CurrentHealth);
        GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, healthMessage);

        if (CurrentHealth <= 0)
        {
            FString deathMessage = FString::Printf(TEXT("You have been killed."));
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, deathMessage);
        }
    }

    //Server-specific functionality
    if (roll == ROLE_Authority)
    {
        FString healthMessage = FString::Printf(TEXT("%s now has %f health remaining."), *GetFName().ToString(), CurrentHealth);
        GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, healthMessage);
    }

    //Functions that occur on all machines. 
    /*  
        Any special functionality that should occur as a result of damage or death should be placed here. 
    */
}

void AThirdPersonMPCharacter::OnRep_CurrentHealth()
{
    OnHealthUpdate();
}

void AThirdPersonMPCharacter::SetCurrentHealth(float healthValue)
{
    if (role == ROLE_Authority)
    {
        CurrentHealth = FMath::Clamp(healthValue, 0.f, MaxHealth);
        OnHealthUpdate();
    }
}

float AThirdPersonMPCharacter::TakeDamage(float DamageTaken, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
    float damageApplied = CurrentHealth - DamageTaken;
    SetCurrentHealth(damageApplied);
    return damageApplied;
}



I’m working through Multiplayer Programming Quick Start | Unreal Engine Documentation.

once I get to 4. Creating a Projectile with Replication

I can only compile the previous steps If I change the code from the above to the below. Compile Errors say I haven’t declared role in each of the "if (role == ROLE_Authority) lines.





    //Client-specific functionality
    if (IsLocallyControlled())


    //Server-specific functionality
    if (ROLE_Authority)
 
}



I’m still learning and after spending all night using documentation, forums, google… im still confused. any help would be appreciated.



role


C++ is a case-sensitive language. “Role” is the actual property you want to compare - however it has been made private as of 4.24 I believe, so you need to call GetLocalRole() now instead.

Thank you.

I’m having some troubles implementing GetLocalRole() into the existing code…

I ended up finding VVV the code below referenced in another post as an alternative.


if (HasAuthority())

but now im curious as what I’m doing wrong with GetLocalRole()

i tried declaring syntax and using it in the cpp, but its just throwing all sorts of errors…

I’m a bit out of my element, but i am convinced that I need to get a better basic picture of networking in action. Thanks again and again all help is appreciated !!

@JGZ:
Same problem here, did your figured out difference of
“if (HasAuthority()” and use of “GetLocalRole()”?
Would be nice when Epic update the tutorial: https://docs.unrealengine.com/en-US/…art/index.html

@all: Or someone else has an advice?

Internally HasAuthority() just calls GetLocalRole() == ROLE_Authority, so it’s essentially the same thing.

Thanks a lot, I thought already its the same, but now we could be sure. Great-