V Mukesh Kumar avatar image
V Mukesh Kumar asked

How to call cloud script function in unreal engine c++

public: void SendCloudFunctionRequest(FString CloudFunctionName, FString guildSearchName); // Delegate to handle the Cloud Function response

 void OnDataRetrieved(const PlayFab::CloudScriptModels::FExecuteFunctionResult& RetrievedData);
 void OnFailure( const PlayFab::FPlayFabCppError& ErrorResult);

void UBaseApiHandler::SendCloudFunctionRequest(FString CloudFunctionName, FString guildSearchName) { PlayFab::UPlayFabCloudScriptAPI CloudScriptAPI; TSharedPtr guildjsonobject = MakeShareable(new FJsonObject()); guildjsonobject->SetStringField(TEXT("searchText"), guildSearchName); guildjsonobject->SetNumberField("page",1); guildjsonobject->SetNumberField("count",1); PlayFab::CloudScriptModels::FExecuteFunctionRequest request; request.FunctionName = CloudFunctionName; request.FunctionParameter = guildjsonobject;

 PlayFab::UPlayFabCloudScriptAPI::FExecuteFunctionDelegate SuccessDelegate;
 SuccessDelegate.BindUObject(this, &ThisClass::OnDataRetrieved);

 PlayFab::FPlayFabErrorDelegate ErrorDelegate;
 ErrorDelegate.BindUObject(this, &ThisClass::OnFailure);
 CloudScriptAPI.ExecuteFunction(request, SuccessDelegate, ErrorDelegate);


this is the code i have written but when i call this function there is some error in delegates and it crashed,

is it the correct function to call?

in BP from playfabsdk i have to call ExecuteFunction but its blueprint internal only function so i am not able to call in cpp

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

Xiao Zha avatar image
Xiao Zha answered

You may use “PlayFabCloudScriptPtr CloudScriptAPI = IPlayFabModuleInterface::Get().GetCloudScriptAPI(); …; CloudScriptAPI->ExecuteFunction(request, SuccessDelegate, ErrorDelegate);” to call ExecuteFunction API. And you may refer to to set the Function parameters.

10 |1200

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

V Mukesh Kumar avatar image V Mukesh Kumar commented ·

thanks for the reply, i have a doubt 1. i got this error LogPlayFabCpp: Error: You must call GetEntityToken API Method before calling this function, do i need to call this every time or only once ? when i call execute function? and this only needs to be called when i call from cpp.

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha V Mukesh Kumar commented ·

As you can see in the API documentation: . The ExecuteFunction Api needs an EntityToken to call. The EntityToken is an access token for PlayFab service and can be automatically set through player login or GetEntityToken method.

Usually, the GetEntityToken Api only need to be called once. As you can see in , it will save the EntityToken into PlayFabSettings for you. In this case, you don’t have to call this Api everytime when you call ExecuetFunction.

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.