API Integration

Latest API version: 1.0.0

Game

CloudArcade API integration for HTML5 games. With game API, you can submit player score and show leaderboard.

Note: Game API won't work with sub-folder installation, since it's referring script from root ("/"), you need to modify script source. Also game API only work with self-hosted games (upload).

Important: If you change or edit game slug, make sure you're also change game folder name same as slug name, or API can't detect current game.

What you can do with game API ?

Let's get started.

First step.

Make sure you're using the latest version of CloudArcade.

Put <script type="text/javascript" src="/js/api.js"> within the <head> section of your index.html (game file).

Then open your browser console log to check if the API is loaded.

Sample code:

Submit score

You can submit a score by calling GameAPI.submit_score(1000);. submit score is also an async function, so you can put "await" on it and do something after the score is already submitted to your server.

Get player/user

Once you calling GameAPI.get_current_user();. You can get or access logged-in player data with GameAPI.current_user;, the value is similar to parsed "data" variable.

Leaderboard

GameAPI.get_scoreboard(conf); have 2 type of parameters as object {type: "top", amount: 10}, amount is how much you want to fetch score data.

Leaderboard "type":

Download sample project here.

You can upload it with "Upload game" section on you admin area.