question

adevill20 avatar image
adevill20 asked

UE4 C++ How to pass Result data

Hey guys.

I'm looking for some help plz. I'm trying to use the Result data from any of the OnSuccess delegates, however I can't seem to get the result passed into another variable for later use.

eg.

//in MyProject.H
void OnLoginSuccess(const PlayFab::ClientModels::FLoginResult& Result) const;

UPROPERTY(Category = "MyProject|PlayFab|Client", BlueprintReadWrite)
FString PlayFabSession;


//In MyProject.CPP
void UNFGameInstance::OnLoginSuccess(const PlayFab::ClientModels::FLoginResult& Result) const
{
	UE_LOG(NF, Log, TEXT("PlayFab : Login Successfull for : %s"), *Result.PlayFabId);
	PlayFabSession = Result.SessionTicket;
}


I'm using the SessionTicket as an example here. How can I get the "Result.SessionTicket" value into the PlayFabSession variable ?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered
5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

adevill20 avatar image adevill20 commented ·

Thanks for the info. I have the problem where the compiler tells me that I cannot set a Fstring = const Fstring.

I see in your internal API the methods are not defined as const, but in the example code (see below) they are all defined as const. Would you be able to give a small example of what I need to do/how to define them ?

 
                  
  1. //Internal
  2. voidUPlayFabClientAPI::OnLoginWithAndroidDeviceIDResult(FHttpRequestPtrHttpRequest,FHttpResponsePtrHttpResponse,bool bSucceeded,FLoginWithAndroidDeviceIDDelegateSuccessDelegate,FPlayFabErrorDelegateErrorDelegate)
  3. {
    1. ClientModels::FLoginResult outResult;
    2. FPlayFabError errorResult;
    3. if(PlayFabRequestHandler::DecodeRequest(HttpRequest,HttpResponse, bSucceeded, outResult, errorResult))
    4. {
      1. if(outResult.SessionTicket.Len()>0)
        1. { mUserSessionTicket = outResult.SessionTicket;
  4. //Example
  5. voidPlayFabApiTest_LoginWithEmail::OnError(constPlayFab::FPlayFabError&ErrorResult)const
  6. {
    1. if(ErrorResult.ErrorMessage.Find(TEXT("password"))==-1)// Check that we correctly received a notice about invalid password
    2. { UE_LOG(LogPlayFab, Error, TEXT("Non-password error with login"));
    3. }
    4. }
0 Likes 0 ·
adevill20 avatar image adevill20 commented ·

I did some reading on const functions/methods and now understand the reason this doesn't work. Would I then just define my variable as mutable (see code below) ? I know these are probably basic questions.

mutable FString PlayFabSession; 
0 Likes 0 ·
adevill20 avatar image adevill20 commented ·

Ok found that "mutable" works 100%, for those stuggeling like me.

0 Likes 0 ·
brendan avatar image brendan adevill20 commented ·

Using mutable does indeed let you assign data to the variable in question from a const function. Making a function const (putting that keywords after the closing parenthesis of the args list) is a "safety" thing, basically saying "make sure no non-static data can be changed" - which includes calling non-static functions. So depending on your own code needs, you could set your variable to be mutable, or you could remove the const specifier for the function. It's really down to how you want to manage the code for your own title.

1 Like 1 ·
adevill20 avatar image adevill20 brendan commented ·

Great, thank you very much for the help.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.