A progressive reward system allows you to reward players for logging in over consecutive days with progressive item grants. This example uses a three-tier reward table providing different items for 2, 5, 7 day log-in streaks. Cloud-Script logic acts as the authoritative server and performs the grant directly into the player's inventory.
- A PlayFab account
- A PlayFab title
At least one of the following:
- To run the Unity sample, an installed copy of the Unity Editor. To install Unity for personal use via Unity Hub, or Unity+ for professional use, see Download Unity.
- A web server to run the Javascript sample.
-
The client calls an authentication method to obtain a session ticket. This is required to make Client API Calls.
-
After logging in, the client calls the PlayFab SDK method
ExecuteCloudScript
to execute a CloudScript method calledCheckIn
. -
CheckIn
performs the following:- Calls the CloudScript method
CheckInTracker
to retrieve the current players ReadOnlyData.- If this is the first login, create a new record.
- Verifies that the player is eligible for a reward:
- Must have logged in to a streak > 1
- Must have been > 24 hrs since last grant
- Must have been < 48 hours after the last grant (otherwise the streak will have been broken)
- Increments the next grant window.
- Write changes back to ReadOnlyPlayerData (
CheckInTracker
). - Read the
ProgressiveRewardTable
key fromTitleData
. - Look up the reward corresponding to the player's login streak.
- Grants the item to the player.
- Returns the details to the client.
- Calls the CloudScript method
Testing Level 2 and 3 rewards requires:
- Either waiting the specified login period.
- or using the Admin API to directly set the Player's data to specific points prior to check-in.
Before you begin, locate the Catalog.json, TitleData.json, and CloudScript.js files. If you have downloaded the repo locally, the JSON files are located in the \Recipes\ProgressiveRewards\PlayFab-JSON folder. The CloudScript.js file is located in the \Recipes\ProgressiveRewards\ folder.
-
Log in to Game Manager.
-
Select your title.
-
In left navigation pane, select Economy, then select the Currency tab.
-
Select New Currency. Enter the following values to create a Virtual Currency:
Property Value Detail Code GM Abbreviation for our VC Name Gems Name of our VC Initial Deposit 5 How many each player gets with a new account -
Select Save Currency.
-
Select the Catalog tab, the select Upload JSON.
-
Select the Catalog.json file, then select Upload File.
-
In left navigation pane, select Content.
-
In the Title Data window, under Title Data select Upload JSON.
-
Select the TitleData.json file, the select Upload.
-
In left navigation pane, select Automation, then select Revisions.
-
Select Upload New Revision, select the CloudScript.js file and then select Save as revision.
Download the PlayFlab Unity 3D SDK from GitHub.
- Open a new or existing project.
- Locate locate the PlayFlab Unity 3D SDK and import it into your Project.
- Locate the ProgressiveRewardsRecipe.unitypackage file and import it into your project. If you have downloaded the repo locally, it is located in the \Recipes\ProgressiveRewards\Example-Unity3d\ folder. Other wise you can download it from the PlayFab-Samples GitHub repo.
- In the Project window, open Assets > PlayFab Recipes > ProgressiveRewards > Scenes and add the ProgressiveReward scene to your Hierarchy.
- In the Hierarchy windows, then select the Main Camera under the ProgressiveRewards scene.
- In the Inspector window, in the Progressive Rewards script component, set Play Fab Title Id to the Title ID for your PlayFab title.
- Run the scene. Call-by-call status updates are displayed in the console.
- Copy the Example-JavaScript folder to your web server. If you have downloaded the repo locally, the folder is located at \PlayFab-Samples-master\Recipes\ProgressiveRewards\Example-JavaScript.
- In your browser, navigate to the index.html page.
- Enter in your title ID
- This example automatically generates a GUID on login. You can instead use and ID for any user that you choose.
- After logging in, the ID is saved into your browser's localstorage
- Open your browser's developer console to see call-by-call status updates.
- For information about debugging CloudScript, see the "Advanced: Debugging CloudScript" section of Writing custom CloudScript.
- For information about Catalogs, see Catalogs.
- For information about Title Data, see Title Data.