Good day.
We has problem with our cloud script call.
Error 400: The script execution was terminated after the maximum execution time limit
This script exchange "Chest_Token" to "Chest_Container". Before grant container we are looking for Token in user inventory and check token parametr as "state" and "date_of_exchange". If all right we grant chest container and revoke token.
But script terminated near "Grant Chest and Revoke Token" part.
But we dont see problem point. Whether the problem is in count of inventory items? Or server.GrantItemsToUser take a lot of time if item "Is stackable"?
Script code:
handlers.grantChest = function (args) // args.ItemInstanceId - chest token item id
{
//inventory
var userInventory = server.GetUserInventory(
{
PlayFabId : currentPlayerId
});
var inventory = userInventory.Inventory;
//find chest token
var tokenItem = getInventoryItem(inventory, args.ItemInstanceId);
if( tokenItem == null )
{
return { status : "ERROR", messageValue: "invalid chest item!" };
}
if( tokenItem.CustomData["State"] != CHEST_TOKEN_STATE_OPENING || Number( tokenItem.CustomData["OpenDate"] ) > Date.now() )
{
return { status : "ERROR", messageValue: "Chest timer NOT done!" };
}
// all right.
//grant chest container
return grantChestImplementation( tokenItem );
}
function grantChestImplementation( tokenItem )
{
//grant Chest to user
var itemGrantResult = server.GrantItemsToUser(
{
CatalogVersion: "chests",
PlayFabId: currentPlayerId,
ItemIds: [ tokenItem.CustomData["Chest"] ]
});
var chestItem = itemGrantResult.ItemGrantResults[0];
//destroy token
server.RevokeInventoryItem(
{
PlayFabId : currentPlayerId,
ItemInstanceId : tokenItem.ItemInstanceId
});
return { status : "OK", messageValue: "All right!", ChestItemId : chestItem.ItemId, ChestCatalog : chestItem.CatalogVersion };
}
function getInventoryItem(arr,ItemInstanceId)
{
for (var k = 0; k < arr.length ; k++)
{
if ( arr[k].ItemInstanceId == ItemInstanceId )
{
return arr[k];
}
}
return null;
}