Game Events & Metadata
Besides answering effects, the game can tell Crowd Control what is happening in it.
Game Events
Game events report notable moments, such as leveling up or defeating a boss. Streamers can hook them up to trigger effects. Events are defined in your Game Pack first; see Game Events for the details. Report one with its ID and arguments:
CrowdControl.trigger_event("level_up", {"levels": 10})
CrowdControl.trigger_event("boss_defeated")Pack Metadata
Metadata is live state of the game. Its main use is filling in variables in effect names and descriptions, see Effect Metadata.
CrowdControl.update_metadata("stars", 120)
CrowdControl.update_metadata_values({"stars": 120, "world": "Lava Cave"})Both functions return false if the update could not be sent, for example because the game is not logged in.
Coins
coins_exchanged is emitted when a viewer exchanges coins on the streamer's channel:
CrowdControl.coins_exchanged.connect(func(amount: int, user: StreamUser):
print("%s exchanged %d coins" % [user.name, amount]))The amount needs the pubsub.private:read scope, which Applications created in the developer portal have. Without it the signal is still emitted, with an amount of 0.
The Streamer
var streamer: StreamUser = CrowdControl.get_streamer_user()
var link: String = CrowdControl.get_interact_link()get_streamer_user() returns the logged in streamer once their profile has loaded. get_interact_link() returns the link viewers use to buy effects on that channel, and launch_interact_link() opens it in the browser.
Next Step
Continue with Starting a Session & Testing.
