question

Anant Sharma avatar image
Anant Sharma asked

CloudScript Grant item to user not working

I have written a custom cloud script function to grant items to user when they create an account for the first time.

I call this function from inside the unity sdk a few seconds after account creation(To avoid granting items to an account which is under creation process on the server)

But the function is not granting the item to the user. i've made usre the item spelling is all correct and it even returns a success callback in the SDK

Please Help

Below is the code of the function:

handlers.GrantFirstTimeItems = function(args)
{


	
	var rewards = "PW-PoorBlaster";
	
	var resultItems = null;
	if(rewards)
	{
		// Grant reward items to player for completing the level
		var itemGrantResult = server.GrantItemsToUser(
		{
			PlayFabId: currentPlayerId,
			Annotation: "Given by completing level "+levelNum,
			ItemIds: rewards
		});
		
		resultItems = itemGrantResult.ItemGrantResults;
	}
	


	return {
		rewards: resultItems
	};
};

    
    
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.

Seth Du avatar image Seth Du ♦ commented ·

Can you provide your Title ID so that I can check the PlayStream events?

1 Like 1 ·
Anant Sharma avatar image Anant Sharma Seth Du ♦ commented ·

3EF10

This is my title id

0 Likes 0 ·

1 Answer

·
Seth Du avatar image
Seth Du answered

I have checked the recent player_executed_cloudscript event. They are all failed due to the same reason:

 "Error": {
      "Error": "CloudScriptNotFound",
      "StackTrace": "",
      "Message": "No function named GrantFirstTimeItems was found to execute"

I have also created a test account in your title (please feel free to delete it) and found that I can reproduce this issue. After checking your code carefully, I believe you miss a right brace in the function RoomEventRaised, so that GrantFirstTimeItems is considered as part of RoomEventRaised. I will suggest adding a right curly brace for handlers.UpdatePlayerStats around line 338 to see if it can fix this issue.

1 comment
10 |1200

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

Anant Sharma avatar image Anant Sharma commented ·

Yes that was the exact problem

thank you so 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.