Integrating Bloxstrap functionality into your game

How can you utilize the features that Bloxstrap has to offer if you’re a game developer on Roblox?

Activity tracking enables Bloxstrap to facilitate one-way data communication between it and Roblox scripts. This feature is called BloxstrapRPC. It lets you send a command from a Roblox script to trigger a function in Bloxstrap. Communication is limited to one command per second.

Here’s a video that shows what it can do, specifically setting a user’s rich presence status while in-game. There is also a demo area for that shows rich presence configuration, courtesy of 1011025m.

The BloxstrapRPC SDK is used to work with BloxstrapRPC from your scripts. It’s a script module that gives you all the necessary tools. Remember, any commands you send must be from the client-side using a LocalScript. You can get it from the Roblox marketplace, roblox-ts, Wally, or GitHub.

Make sure you know about all the types and methods it offers. Luau and Typescript linting can assist you, but they’re also listed below for your reference.

Example usage

local BloxstrapRPC = require(game.ReplicatedStorage.BloxstrapRPC)

 

local timestamp = os.time()

 

BloxstrapRPC.SetRichPresence({

details = “Example details value”,

state = “Example state value”,

timeStart = timestamp,

timeEnd = timestamp + 60,

largeImage = {

assetId = 10630555127,

hoverText = “Example hover text”

},

smallImage = {

assetId = 13409122839,

hoverText = “Example hover text”

}

})

Module exports

RichPresence {

details:     string?,

state:       string?,

timeStart:   number?,

timeEnd:     number?,

smallImage:  RichPresenceImage?,

largeImage:  RichPresenceImage?

}

 

RichPresenceImage {

assetId:     number?,

hoverText:   string?,

clear:       boolean?,

reset:       boolean?

}

Functions

SendMessage(command: string, data: any)   — Used for sending an RPC message. Avoid using this, as every command available will have a dedicated function for it.

SetRichPresence(data: RichPresence)       — Used for configuring the user’s Discord rich presence activity.

Additional information

When you’re creating a RichPresence type, here’s what you need to think about.

  1. If a value is nil or not set, it means that the rich presence should keep its current value.
  2. By default, field values will stay the same. This means you don’t have to reset the entire presence just to update one field.
  3. The timeStart and timeEnd values should be UTC epoch timestamps in seconds, which can be obtained with os.time().
  • If ‘timeEnd’ is not given, the presence will display the time that has passed since ‘timeStart’.
  • Otherwise, it will display the time remaining until ‘timeEnd’.
  1. For erasing fields:
  • You can set string properties as an empty string.
  • Number properties can be set to zero.
  • RichPresenceImage property types can have their ‘clear’ property set to true.
  1. For reverting fields to their defaults:
  • string property types can be set as “<reset>”.
  • RichPresenceImage property types can have their ‘reset’ property set to true.

Implementation

This part explains how BloxstrapRPC works in the application. If you want to implement BloxstrapRPC (like creating a standalone cross-platform rich presence server), continue reading.

BloxstrapRPC traces Roblox’s log file while it’s running, searching for print entries that start with [BloxstrapRPC]. After this identifier, there’s a message in JSON format with attributes for command and data. The command is the procedure to execute, and data is the data it should use. It’s quite simple.

This allows scripts to send data to external applications by printing a string to the output. To show you better, here’s what the BloxstrapRPC Helper Module is basically doing:

print(‘[BloxstrapRPC] {“command”: “SetRichPresence”, “data”: {“details”: “hi”}}’)

The goal of BloxstrapRPC is to become the standard for Roblox scripts to communicate data to external applications, not just for use in Bloxstrap. For instance, if you’re creating your own Roblox rich presence handler application and you want games to set their own rich presence, it’s better to follow BloxstrapRPC instead of creating your own system, if possible. This approach reduces the need to worry about implementation details and ensures compatibility with many Roblox games.

Leave a Comment