-
Notifications
You must be signed in to change notification settings - Fork 56
Triggering Cooldowns
A single button may be seen by thousands of viewers. The action that button causes may not make sense to spam thousands of times per second so you may want to put buttons on a "cooldown" timer before allowing them to be pressed again. Take a look at this snippet:
// Look for a cooldown metadata property and tigger it if it exists.
long long cooldown = 0;
int err = interactive_control_get_meta_property_int64(session, "button1", "cooldown", &cooldown);
if (MIXER_OK == err && cooldown > 0)
{
interactive_control_trigger_cooldown(session, "button1", cooldown * 1000));
}
The code above assumes that you have added a metadata property to the button with the key "cooldown" and a number value that represents the number of seconds the button should cooldown after being pressed.
Due to the fact that the game client initiates cooldowns on buttons, there may be button presses that come in before the cooldown can be triggered and enforced by the interactive session. Therefore it is good practice to hold some internal game state about which buttons are on cooldown so you can efficiently ignore buttons presses that are not valid.