Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

I got a little problem over here

A topic by Dm0ll created May 24, 2024 Views: 197 Replies: 8
Viewing posts 1 to 2
Submitted

I'm not using any engines, so I think I won't be able to use loot locker, and a speedrun.com leaderboard would take a lot of time to be accepted by the speedrun.com mods, and they'd probably reject my game, since it won't be that complicated of a game. They only accept games that take long times to beat. Can people send me prints of their score via emails so every day I manually update the leaderboard?

Loot locker has an API, so you can just make calls from virtually any programming language you’re working with. (https://ref.lootlocker.com/game-api/#introduction)

Submitted

Just asking, can I do the method I said? Like people take screenshots of their scores and post it on the games comments, then I manually change the leaderboard

(1 edit)

Technically you don’t HAVE to have a leaderboard, so you can do this, although I would recommend just using the API, because it’s really not that hard. It’s really just one request for submitting a score, and another one for getting the leaderboard. It will make your game sustain itself, not depending on you checking the comments.

So yes, you can, but it’s less than not recommended.

Submitted

But the thing is: HOW am i going to use the API? I need to import it to my program, but i don`t see a python version of this  API

(1 edit)

It's a REST API, you just need to send HTTP requests

(3 edits)

The API is fully accessible with HTTP.

The requests library is something you WILL encounter when using python. It is used for sending HTTP requests.

py -m pip install requests

The docs: https://requests.readthedocs.io/en/latest/

How you could go about doing this: Look at the cURL template on the loot locker API docs for making a session:

curl -X POST "https://api.lootlocker.io/game/v2/session/guest" \
  -H "Content-Type: application/json" \
  -d "{\"game_key\": \"your_game_key\", \"game_version\": \"0.10.0.0\"}"

What you can see: The mode is POST to the url “https://api.lootlocker.io/game/v2/session/guest”. The HTTP Headers (-H argument) are made of key-value pairs (like dictionaries). The key is “Content-Type” and the value is “application/json”. This is standard HTTP. Now to the loot locker specific stuff. The -d argument is the data you send. Here, this is {“game_key”: some_game_key, “game_version”: some_version}.

To transfer this to python:

import requests

GAME_KEY = "my_key"
GAME_VERSION = "1.0.0"

url = "https://api.lootlocker.io/game/v2/session/guest"

# This is the -H argument as a dict
headers = {
    "Content-Type": "application/json"
}

# This is the -d argument as a dict
data = {
    "game_key": GAME_KEY,
    "game_version": GAME_VERSION
}

# Since dicts are (basically) in JSON format, you can specify these as the data
# requests.post returns requests.Response, from which you can get the status_code and other information
r = requests.post(url, headers=headers, json=data)

The same thing can be done for getting the leaderboard. The API Docs show you, that the response will look something like this:

{
  "success": true,
  "session_token": "e6fa44946f077dd9fe67311ab3f188c596df9969",
  "player_id": 3,
  "public_uid": "TSEYDXD8",
  "player_identifier": "ec9b35e6-b184-4f34-b49f-980f86b291e2",
  "player_created_at": "2022-05-30T07:56:01+00:00",
  "check_grant_notifications": true,
  "check_deactivation_notifications": false,
  "seen_before": true
}

Now by accessing r.json().get("session_token") for example, we can get the session_token, which we can later use to save the score to the leaderboard.

IN SHORT:

  1. Look at the cURL template
  2. Convert -H and -d to dicts
  3. POST to the URL of the API
  4. Evaluate the Response
  5. Repeat

If you need help with anything, hit me up on discord (@fabianbuthere)!

(Sorry for the lengthy answer, I’m used to StackOverflow)

Submitted

Usually i post the source code for linux users to play the game too, but I guess that i can't do that for this game since someone could just get the game id and send fake requests with higher scores

Submitted (1 edit)

Thanks Bro! I ran into some issues but figured it out later. Thanks! if it wasn't you, i'd be stuck in this for the whole day