Construct Guide
This guide will walk you through integrating your Construct game with the Basement.fun platform using web APIs
Events
Construct has a great GUI that enables developers to create games with minimal to no code. The following docs will review how to connect your game to Basement.fun using Construct's event sheet.
Key Components
You will need to add a few objects to your project to enable your Construct game to interact with the Basement.fun platform.
To add objects to your project go to the Layout View, right-click in the layout, select Insert New Object, and then choose the object you want to insert into your project. After adding the object, it will be available in your event sheet.
Sample Event
This sample event will cover the POST Set Scores request detailed in the BSMNT API Specs.
Sample Request
Create Function
Right-click anywhere on the event sheet, create a function, and name it SetScore.
Set Service Method Header
Click add action, select AJAX, select Set request header.
- Header field:
X-Service-Method - Value field:
setUserScore
Set Authorization Header
Add another AJAX action and select Set request header again.
- Header field:
Authorization - Value field:
Bearer <game secret>
Replace <game secret> with your actual game secret token.
Configure POST Request
Add another AJAX action but this time, select Post to URL. Enter the following:
- Tag:
setUserScore - URL:
https://api.basement.fun/launcher - Data:
{"launcherJwt": "string", "nonce": "string", "score": 0} - Method:
POST
This is a sample request - be sure to replace your values with variables that are set by events in your game.
Sample Response
The sample response will look something like this:
json{ "success": true | false, "error"?: "error string", "newScore"?: { "_id": "unique id", "nonce": "nonce", "updatedAt": 23151264, // unix timestamp "score": 100.235, "gameId": "game uuid", "normalizedAddress": "user lowercase address" } }
Retrieving Data
In Construct, let's retrieve the nonce from the response, so we can use it to retrieve the score at a later time.
Create Global Variable
Right-click anywhere on the event sheet and add a global variable named Nonce.
Add Trigger Event
Add an event that is triggered by your game.
Example: To capture the user's score when they crash their bike into another bike, add an on collision with another object condition to the biker and set the object to biker.
Call SetScore Function
Add the action, select functions, and select SetScore.
Parse JSON Response
Add a JSON action, select parse, and enter AJAX.LastData in the JSON string field.
This will grab the response from our SetScore request.
Extract Nonce Value
Add a system action, select set value, choose the Nonce variable, and enter JSON.Get("newScore.nonce").
Now your Nonce variable is set to the nonce returned by the API response!
Complete Integration
Following the same steps, you can create events for each API endpoint by reviewing all the parameters and responses.
Available API Endpoints
Update or set a user's score for leaderboards.
Endpoint: POST /launcher
Headers: X-Service-Method: setUserScore
json{ "launcherJwt": "string", "nonce": "string", "score": 0 }
Retrieve a user's current score.
Endpoint: GET /launcher
Headers: X-Service-Method: getUserScore
Trigger onchain actions based on game events.
Endpoint: POST /launcher
Headers: X-Service-Method: triggerRulesEngine
json{ "launcherJwt": "string", "trigger": "string", "nonce": "string" }
Best Practices
Next Steps
Troubleshooting
- Ensure you've added the AJAX object to your project
- Check that all required headers are set correctly
- Verify your game secret is valid
- Make sure the API endpoint URL is correct
- Confirm the JSON object is added to your project
- Check that
AJAX.LastDatacontains valid JSON - Use the Browser object to log the raw response for debugging
- Verify your launcher JWT token is valid
- Check that the Authorization header is properly formatted
- Ensure your game secret hasn't expired