Skip to content

Install SDK

TypeScript

Quick Start

  1. Install the Balancy SDK package:

    npm i --save @balancy/core@next
    npm i --save @balancy/cli@next
    
  2. Simple example how to run everything

    import {
       AppConfig,
       Balancy,
       Environment,
       Platform,
    } from '@balancy/core';
    
    (async () => {
       //TODO add your game id and public key
       const config = AppConfig.create({
          apiGameId: "6f5d4614-36c0-11ef-9145-066676c39f77",
          publicKey: "MzA5MGY0NWUwNGE5MTk5ZDU4MDAzNT",
          environment: Environment.Development,
       });
    
       config.platform = Platform.AndroidGooglePlay;
       config.deviceId = "TestDevice";
       config.customId = "Custom456";
       config.appVersion = "1.0.0";
       config.engineVersion = "TypeScript_1.0";
    
       Balancy.Callbacks.initExamplesWithLogs();
    
       await Balancy.Main.init(config);
    })();
    
  3. You can clone a complete working example from our public git project Balancy TypeScript Example

Additional Methods

There are several npm commands that can be used to configure the Balancy SDK. These commands are part of the @balancy/cli package. Before you can access them you need to add 'balancy' parameter to your package scripts. Your package.json can look like this:

{
  "name": "balancy-demo",
  "version": "1.0.0",
  "main": "index.tsx",
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "balancy": "balancy"
  }
}

"balancy": "balancy" - this line allows you to run balancy commands from the terminal.

Authentication

To authenticate the Balancy SDK, you need to run the following command:

npm run balancy -- config-login -e <email> -p <password> -c .balancy

You have to use your email and password from the Balancy Dashboard. That command creates a file folder .balancy and a file called user.info. After a successful login, your email and token are saved in this file. The best practice would be to 'gitignore' this folder, to avoid sharing your token with other developers. Once the file is created you'll be able to use the Balancy SDK commands without the need to log in again, all futher commands just require the -c .balancy parameter, so the SDK knows where to find the user.info file.

Get Game List (Optional)

npm run balancy -- config-list-games -c .balancy

This command will list all the games you have access to. You can find the game id in the list.

Select Game

npm run balancy -- config-select-game -c .balancy -g 6f5d4614-36c0-11ef-9145-066676c39f77

This command selects the game you want to work with. You need to provide the game id from the previous command. Alternatively, you can use the game id from the Balancy Dashboard. Selected game is save in the 'user.info' file. You can edit this file manually, if you don't want to use the command.

List Branches

npm run balancy -- config-list-branches -c .balancy

This command lists all the branches in the selected game. You'll need the branch id to select the branch.

Select Branch

npm run balancy -- config-select-branch -c .balancy -b 0

This command selects the branch you want to work with. You need to provide the branch id from the previous command. Selected branch is save in the 'user.info' file. You can edit this file manually, if you don't want to use the command.

Generate Code

npm run balancy -- config-generate -c .balancy -p src/auto-generated-code

This command generates the code for the selected branch. You need to provide the path where the code should be saved. In the example above the code is generated in the 'src/auto-generated-code' folder.

When the code is generated you can import it in your project:

import 'auto-generated-code/index';

Download Configs

npm run balancy -- config-download -c .balancy -p src/resources

This command downloads the configs and assets for the selected branch. You need to provide the path where the configs should be saved. In the example above the configs are saved in the 'src/resources' folder. The app can usually includes some configs, so it could run without the need to download them from the server or when there is no connection.

Cocos Creator

TO be added...

Unity

TO be added...