question

Reid Taylor avatar image
Reid Taylor asked

Cloud script calling server api functions

Hello, I am working on 2 way confirmation friend request and I have a dilemma... this is my cloud function:

handlers.SendFriendRequest = function(args, context) {
    var player1Id = currentPlayerId;
    var player2Id = null;
    
    if (args && args.friendId) player2Id = args.friendId;
    
    // Make Player 2 a Friend of Player 1
    var request = {
        PlayFabId: player1Id,
        FriendPlayFabId: player2Id,
    };
    var result = server.AddFriend(request);
    // Make Player 2 a Friend of Player 1
    
    // Make Player 1 a Friend of Player 2
    request = {
        PlayFabId: player2Id,
        FriendPlayFabId: player1Id,
    };
    result = server.AddFriend(request);
    // Make Player 1 a Friend of Player 2
}

So right now it should only make the add friend mutual.(So both players are friends with the other)

The problem is the cloud callback function gets called when the cloud runs this function. But I want to wait until the cloud script has called the function and the friends have been added before the call back is called.

So in short how can I wait till a server api call has been made before sending cloud callback.? Thanks!

CloudScriptFriends
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

·
Reid Taylor avatar image
Reid Taylor answered

Please Correct me if I'm wrong.. But from testing it looks like it automatically waits until all Api calls have finished. This is just apparent not factual :)

2 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.

Rick Chen avatar image Rick Chen ♦ commented ·

The CloudScript function is synchronous function. Generally, it will return the result after the server API calls inside are executed.

0 Likes 0 ·
Reid Taylor avatar image Reid Taylor Rick Chen ♦ commented ·

Ahhh... ok Thanks!

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.