Start typing to search...
Tutorials
Creating games on Koji
1. Setting up koji.json
Search

Setting up koji.json

In the first section of this tutorial, you will add the in-app purchase entitlement and define a price value that can be customized when someone remixes your game.

By the end of this section, you should feel comfortable:

  • Defining entitlements and remix values in koji.json.

Forking the game template

Get started by cloning the Tower Stack game to your own project.

  1. Open the Tower Stack game.

  2. Click the Koji button in the top right, and then click Advanced > Fork.

    Koji button

    A copy of the project is created in your Koji account, and the Project Details page for your new project is displayed.

  3. Click Open in Code Editor.

    The Koji editor opens with the game code loaded.

Note
The Koji editor is recommended for this tutorial, but you’re free to clone the newly created project to your local environment if you prefer.

Defining entitlements

First, you need to enable Koji’s in-app purchases feature for your new game template.

Open the file koji.json, which is located in the root of the project. Find the following section of code.

...

"entitlements": {
    "InstantRemixing": true,
    "InstantRemixingNativeNavigation": true,
    "FeedEvents": true,
    "CustomMetadata": {
        "enabled": true,
        "metadata": {
        "title": "{{remixData.title}}",
        "description": "How high can you stack them?"
        }
    }
},

...

This code defines an entitlements object, which contains a number of properties that define how the application works on the Koji platform.

Add a new property called InAppPurchases, as follows.

"entitlements": {
    "InstantRemixing": true,
    "InstantRemixingNativeNavigation": true,
    "FeedEvents": true,
    "CustomMetadata": {
        "enabled": true,
        "metadata": {
        "title": "{{remixData.title}}",
        "description": "How high can you stack them?"
        }
    },
    "InAppPurchases": {
        "enabled": true,
        "products": [
            {
                "sku": "extraLives",
                "name": "Extra Lives",
                "price": "{{remixData.price}}",
                "isConsumable": true
            }
        ]
    }
},

InAppPurchases is defined as an object, and it contains an array of products. You’re only selling one product — extra lives — so you only have one product in the array. The product is defined as follows.

{
    "sku": "extraLives",
    "name": "Extra Lives",
    "price": "{{remixData.price}}",
    "isConsumable": true
}

Here’s a breakdown of the properties:

  • sku – Identifier used to look up the product when the user makes a purchase.

  • name – Product name that appears on the user’s receipt.

  • price – Price of the product in USD. This value is set to {{remixData.price}}, which means the price will use a custom value. You will define the custom value in the next step.

  • isConsumable – Feature that determines whether the product can be purchased more than once. This value is set to true, which allows the user to purchase the product multiple times.

Defining remix data

In koji.json, scroll down to the remixData object. This is where you define the customizable values that users can modify when remixing the template.

Add a price property and set it to 0.1 for now.

"remixData": {
    ...
    "price": 0.1
  },
Note
To register the product, the price value must be greater than 0 and you must deploy a build of your game. For example, by publishing it from the Koji editor. Registering the product will enable you to test purchases in the debugger, which you will do later in the tutorial.

Wrapping up

In this section, you set up the product and price information for extra lives in your game.

In the next section, you’ll create the menu that enables players to purchase more lives when they run out.