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"></script>
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:
You can submit a score by calling ca_api.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.
Once you calling ca_api.get_current_user();
. You can get or access logged-in player data with ca_api.current_user;
, the value is similar to parsed "data" variable.
ca_api.get_scoreboard(conf);
have 2 type of parameters as object {type: "top", amount: 10}
, amount is how much you want to fetch score data.