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.
Browser Object
The Browser object enables you to write to the console. It’s not necessary, but it will come in handy when verifying data and debugging your code.
AJAX Object
The AJAX object enables your game to interact with B3 APIs.
- POST requests require you to create separate actions for each header parameter and one post to URL action for all the body parameters
- GET requests require you to combine all the parameters and values you need into a single URL to send the request to the API
- The API responses can be referenced using
AJAX.LastData
JSON Object
The JSON object enables your game to handle JSON responses. You will need to parse the JSON strings to make use of the response data.
Sample Event
This sample event will cover the POST Set Scores request detailed in the BSMNT API Specs.Sample Request
1
Create Function
Right-click anywhere on the event sheet, create a function, and name it SetScore.
2
Set Service Method Header
Click add action, select AJAX, select Set request header.
- Header field:
X-Service-Method
- Value field:
setUserScore
3
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.4
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:API Response
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.1
Create Global Variable
Right-click anywhere on the event sheet and add a global variable named Nonce.
2
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.
3
Call SetScore Function
Add the action, select functions, and select SetScore.
4
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.
5
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
Set User Score
Set User Score
Update or set a user’s score for leaderboards.Endpoint:
Headers:
POST /launcher
Headers:
X-Service-Method: setUserScore
Get User Score
Get User Score
Retrieve a user’s current score.Endpoint:
Headers:
GET /launcher
Headers:
X-Service-Method: getUserScore
Trigger Rules Engine
Trigger Rules Engine
Trigger onchain actions based on game events.Endpoint:
Headers:
POST /launcher
Headers:
X-Service-Method: triggerRulesEngine
Best Practices
Error Handling
Always check the
success
field in API responses and handle errors gracefully.Variable Management
Use Construct’s global variables to store important data like JWT tokens and user scores.
Debug Console
Use the Browser object to log important information to the console during development.
API Rate Limits
Be mindful of API rate limits and avoid making too many requests in quick succession.
Next Steps
BSMNT API Documentation
Complete API reference for all available endpoints
Game Launcher Guide
Learn how to integrate with the BSMNT game launcher
Construct Documentation
Official Construct 3 documentation and tutorials
Example Projects
Sample projects using BSMNT integration
Troubleshooting
AJAX requests not working
AJAX requests not working
- 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
JSON parsing errors
JSON parsing errors
- Confirm the JSON object is added to your project
- Check that
AJAX.LastData
contains valid JSON - Use the Browser object to log the raw response for debugging
Authentication issues
Authentication issues
- Verify your launcher JWT token is valid
- Check that the Authorization header is properly formatted
- Ensure your game secret hasn’t expired