Variables
Variables are your own named values, kept on Streamed: a death counter, a goal, a text. You create and change them on the dashboard's Variables page. Tips add up in the built-in ones. Widgets can read them and are told at once when one changes, but cannot change them.
Reading a variable
SE_API.counters.get('deaths').then((counter) => {
document.getElementById('deaths').textContent = counter.value;
});counters.get(name) resolves to { id, counter, count, value }; count and value are the same.
- The name is matched in lowercase.
- A value that looks like a number (
12,-3.5) is a number; anything else is a text. - A variable that does not exist reads
0.
The values are already in the widget when it loads, so counters.get answers at once.
When a variable changes
Every change (also creating and deleting one) fires onEventReceived with the listener bot:counter, in every open custom widget of yours, at once:
window.addEventListener('onEventReceived', (obj) => {
const { listener, event } = obj.detail;
if (listener === 'bot:counter' && event.counter === 'deaths') {
document.getElementById('deaths').textContent = event.value;
}
});{ "listener": "bot:counter", "event": { "counter": "deaths", "value": 12 } }A deleted variable arrives with the value 0. bot:counter never waits in the event queue.
Names and values
A name has at most 32 characters: lowercase letters without accents, digits and _, starting with a letter (my_counter). A value is at most 500 characters. Numbers are kept with a decimal point (12,5 is saved as 12.5). An account has at most 100 variables.
Built-in tip variables
Accounts that get tips (Ko-fi, or YouTube's Super Chats) have these, and every tip is added to them, test tips too (deleting a test tip from the event history takes it back). You can change them on the dashboard like your own.
| Variable | Session data key | Value |
|---|---|---|
tip_total |
tip-total |
all tips |
tip_goal |
tip-goal |
your goal; only you set it |
tip_session |
tip-session |
this stream; starts again when you go live |
tip_week |
tip-week |
this week; starts again on Monday |
tip_month |
tip-month |
this month; starts again on the 1st |
tip_count |
tip-count |
the number of tips |
In the session data, the keys in the middle column hold these values (as { amount }, tip-count as { count }), instead of counting events like the other keys do. That needs a widget connected to a platform that sends tips; tip-goal is there for every widget. A change of a tip variable fires both bot:counter and onSessionUpdate.
Weeks and months follow the calendar in the server's time zone. Super Chats count in these variables, but are superchat events, so they are not in tip-latest or tip-recent.
Elsewhere in Streamed
The same variables are used in two more places:
- Alert texts of the Alerts widget:
%var:deaths% - The bot's messages:
{var:deaths}
Anyone who knows the link of one of your overlays can read your variables.