Skip to content

Commit dd3d296

Browse files
add clarifying language around the use of global variables (#374)
1 parent 6e2d02c commit dd3d296

File tree

5 files changed

+87
-57
lines changed

5 files changed

+87
-57
lines changed

streamerbot/2.guide/03.variables.md

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ description: Usage of arguments and variables in your Streamer.bot actions
44
---
55

66
## Introduction
7-
When a trigger executes an action, it will automatically generate a set of variables specific to that event source and make them available to that action via the **argument stack**. You can use subsequent sub-actions to populate additional arguments, or even manipulate existing arguments on the stack.
7+
When a trigger executes an action, it will automatically generate a set of variables specific to that event source and type, and make them available to that action via the **argument stack**. You can use subsequent sub-actions to populate additional arguments, or even to manipulate existing arguments on the stack.
88

9-
Arguments only persist until the called action finishes execution and can not be referenced by any other action. To share variables across multiple actions, or to persist them across restarts, you can store them as [Global Variables](#global).
9+
Arguments only exist within the scope of the current action. Once the action finishes execution, they can not be referenced by any other action. To share variables across multiple actions, or to persist them across restarts, you can store them as [Global Variables](#global-variables).
1010

1111
::read-more{to=/api/triggers}
1212
Explore all available triggers and their variables in the [Triggers API References](/api/triggers)
@@ -24,12 +24,12 @@ These variables can be utilized in most [sub-action](/guide/actions#sub-actions)
2424

2525
![Using variables within a text field](assets/variable-example.png){caption-alt}
2626

27-
To use a variable from the current argument stack, wrap the variable name with `%` symbols:
27+
To replace a variable name with its value from the current argument stack, wrap the variable name with `%` symbols:
2828

2929
`%userName%`{lang=cs}
3030

3131
::tip
32-
Variables are added onto the argument stack during sequential execution of each sub-action. If you are testing and a variable seems to be missing, ensure that you are testing at the correct point of execution!
32+
Variables are added to the argument stack by each sub-action, which execute sequentially. If you are testing and a variable seems to be missing, ensure that the sub-action which sets it runs *before* you're attempting to access it!
3333
::
3434

3535
::read-more{to=#inspecting-arguments}
@@ -39,25 +39,35 @@ Read more about how to **inspect arguments** after an action has executed
3939
### Global Variables
4040
Global variables allow you to share data between multiple actions, or even persist it across multiple restarts of Streamer.bot.
4141

42-
To quickly access a global variable, wrap the variable name with `~` symbols:
42+
::tip{to=/api/sub-actions/core/globals/global-set}
43+
To set the value of of a global variable in your action, call the `Set Global Variable` sub-action<br/>
44+
:icon{name=i-mdi-alert} This **does not** also make the global variable's value available in your action
45+
::
46+
47+
::warning{to=/api/sub-actions/core/globals/global-get}
48+
To access the value of a global variable in your action, you **must *first*** assign it to a local variable with the `Get Global Variable` sub-action
49+
::
4350

44-
`~myGlobalVariable~`{lang=cs}
51+
To directly access the value of a ***persisted* global variable**, wrap the variable name with `~` symbols:
52+
53+
`~myPersistedGlobalVariable~`{lang=cs}
4554

4655
::tip
47-
This syntax currently only works for **persisted** global variables, and **not** user variables.
56+
This syntax currently *only* works for **persisted** global variables, and **not** user global variables.
4857
::
4958

50-
::read-more{to=#inspecting-arguments}
51-
Read more about how to use the variable viewer to **view all of your global variables in one place!**
59+
60+
::read-more{to=#global-variable-viewer}
61+
Read more about how to use the global variable viewer to **view all of your global variables in one place!**
5262
::
5363

5464
:read-more{to=/api/sub-actions/core/globals}
5565

5666
#### User Global Variables
57-
User variables function as global variables, but store values **per user**.
67+
User global variables function as global variables, but store values **per user**.
5868

5969
::tip
60-
User variables can be useful for creating per-user counters, leaderboards, or anything you can think of!
70+
User global variables can be useful for creating per-user counters, leaderboards, or anything you can think of!
6171
::
6272

6373
### Generic
@@ -189,34 +199,34 @@ $parse(line%i%)$
189199
// ==> returns value of %line1% (the second line of the file)
190200
```
191201
::tip
192-
`%arguments%` and `~persistedVariables~` will be parsed in `parse`'s parameter, but not other `$inline()$` functions. If you wish to use a function, then set another argument to the output of the function, and use that argument in the `parse` instead.
202+
`%arguments%` and `~persistedGlobalVariables~` will be parsed in `parse`'s parameter, but not other `$inline()$` functions or formatting. If you wish to use another function, set another argument to the output of the function, and use that argument in `parse` instead.
193203
::
194204

195-
## Variable Viewer
196-
The Variable Viewer in Streamer.bot provides a convenient location to **view, modify, and create** all types of global variables, including per-platform user variables.
205+
## Global Variable Viewer
206+
The global variable viewer in Streamer.bot provides a convenient location to **view, modify, and create** all types of global variables, including per-platform user global variables.
197207

198-
You can open the variable viewer at any time by clicking `Variables` on the Streamer.bot toolbar:
199-
![Variable Viewer Button](assets/variable-viewer-button.png)
208+
You can open the global variable viewer at any time by clicking `Global Variables` on the Streamer.bot toolbar:
209+
![Global Variable Viewer Button](assets/variable-viewer-button.png)
200210

201211
You will be greeted with a popup window:
202212
![View Global Variables](assets/variable-viewer-globals.png)
203213

204214
::tip
205-
Variables are **updated in real-time**, making this view extremely useful while you create and test your actions!
215+
Global variables are **updated in real-time**, making this view extremely useful while you create and test your actions!
206216
::
207217

208218
### Options
209-
#### Add/Edit Variables
219+
#### Add/Edit Global Variables
210220
Selecting `Add` or `Edit` from the [context menu](#variables-context-menu) will greet you with the following options:
211-
![Variable Viewer Edit Dialog](assets/variable-viewer-edit-dialog.png)
221+
![Global Variable Viewer Edit Dialog](assets/variable-viewer-edit-dialog.png)
212222

213223
::field-group
214224
::field{name="Variable Name" type="Text" required}
215-
Enter the name for your new variable
225+
Enter the name for your new global variable
216226
::
217227

218228
::field{name="Value" type="Text" required}
219-
Enter a new value for this variable
229+
Enter a new value for this global variable
220230
::
221231

222232
::field{name="Auto Type" type="Toggle"}
@@ -230,28 +240,28 @@ Selecting `Add` or `Edit` from the [context menu](#variables-context-menu) will
230240
::
231241
::
232242

233-
#### Variables Context Menu
243+
#### Global Variables Context Menu
234244
The <kbd>Right-Click</kbd> context menu provides the following options:
235245

236246
::field-group
237247
::field{name="Add Variable"}
238-
Create a new variable of the current category type (e.g. persisted, non-persisted)
248+
Create a new global variable of the current category type (e.g. persisted, non-persisted)
239249
::
240250

241251
::field{name="Edit Variable"}
242-
Edit the selected variable, see configuration options above
252+
Edit the selected global variable, see configuration options above
243253
::
244254

245255
::field{name="Delete Variable"}
246-
Remove the selected variable
256+
Remove the selected global variable
247257
::
248258

249259
::field{name="Copy Variable Name"}
250-
Copy the selected variable name to your clipboard
260+
Copy the selected global variable name to your clipboard
251261
::
252262

253263
::field{name="Delete all Variables"}
254-
Remove **all** variables from the current category type (e.g. persisted, non-persisted)
264+
Remove **all** global variables from the current category type (e.g. persisted, non-persisted)
255265
::
256266
::
257267

@@ -260,17 +270,17 @@ The <kbd>Right-Click</kbd> context menu provides the following options:
260270
Navigate to `Action Queues > Action History` in Streamer.bot
261271
::
262272

263-
From the `Action History` view, you can <kbd>Right-Click</kbd> an action execution to inspect all variables on the argument stack:
273+
From the `Action History` view, you can <kbd>Right-Click</kbd> an action execution to inspect all variables from that action's argument stack:
264274

265275
![Action History Context Menu](assets/action-history-context-menu.png)
266276

267277
::field-group
268278
::field{name="Inspect Variables When Queued"}
269-
View all variables on the argument stack **before** the action has started
279+
View all variables on the argument stack from **before** any of the sub-actions had run
270280
::
271281

272282
::field{name="Inspect Variables After Run"}
273-
View all variables on the argument stack **after** the action has completed
283+
View all variables on the argument stack from **after** the action had completed
274284
::
275285
::
276286

@@ -280,5 +290,5 @@ When you select one of these options, you will be greeted with a dialog containi
280290
![Action History Variables](assets/action-history-variables.png)
281291

282292
::tip
283-
You can use this dialog any time you want to know what variables are populated by a trigger
293+
You can use this dialog any time you want to know what variables are populated by a trigger or the sub-actions during a specific run of an action
284294
::

streamerbot/3.api/1.sub-actions/core/globals/global-get.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
title: Get Global Variable
33
description: Fetch the value of a global variable and populate a local argument
44
parameters:
5-
- name: GlobalVariableSource
6-
- name: GlobalVariablePersisted
5+
- name: Source
6+
- name: Persisted
77
- name: Variable Name
88
type: Text
99
required: true
1010
description: |
11-
Enter the name of the variable you would like to fetch
11+
Enter the name of the global variable you would like to fetch
1212
1313
::warning
14-
`Variable Name` must be entered in `camelCase` (the first letter must be lowercase)
14+
This is the **name** of the global variable, which means it should not be wrapped in `%` symbols unless you specifically want to use the **value** of a local variable in the **name** of your global variable
1515
::
16+
1617
- name: Destination Variable
1718
type: Text
1819
required: true
@@ -22,6 +23,11 @@ parameters:
2223
::tip
2324
It is recommended to use a **different name** than the global variable name
2425
::
26+
27+
::warning
28+
This is the **name** of the destination variable, which means it should not be wrapped in `%` symbols unless you specifically want to use the **value** of a local variable in the **name** of your destination variable
29+
::
30+
2531
- name: Default Value
2632
type: Text
2733
description: |
@@ -36,8 +42,8 @@ csharpMethods:
3642
---
3743

3844
::tip
39-
You can quickly access persisted globals without this sub-action by wrapping the name with `~`<br>
40-
:icon{name=i-mdi-chevron-right} `~myGlobalVariable~`{lang=cs}
45+
You can directly access the value of **persisted** non-user globals without this sub-action by wrapping the name with `~`<br>
46+
:icon{name=i-mdi-chevron-right} `~myPersistedGlobalVariable~`{lang=cs}
4147
::
4248

4349
:read-more{to=/guide/variables}
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
---
22
title: Set Global Variable
3-
description: Create or update a global variable
3+
description: Create or update the value of a global variable
44
parameters:
5-
- name: GlobalVariableSource
6-
- name: GlobalVariablePersisted
5+
- name: Destination
6+
- name: Persisted
77
- name: Variable Name
88
type: Text
99
required: true
1010
description: |
11-
Enter the name of the variable you would like to create or modify
11+
Enter the name of the global variable you would like to create or update
1212
1313
::warning
14-
`Variable Name` must be entered in `camelCase` (the first letter must be lowercase)
14+
`Variable Name` is the **name** of the global variable, which means it should not be wrapped in `%` symbols unless you specifically want to use the **value** of a local variable as the **name** of your global variable
1515
::
16-
- name: Source
17-
type: Select
18-
default: Argument
19-
required: true
20-
description: |
21-
Select the source for the value to assign to the global variable
2216
23-
- `Argument` - Use the value of an argument
24-
- `Value` - Assign any arbitrary value
25-
- `Increment` - Add to an existing `int`{lang=cs} variable
26-
- `Decrement` - Subtract from an existing `int`{lang=cs} variable
2717
- name: Value
2818
type: Text
2919
required: true
3020
description: |
31-
Enter the value to assign to the global variable, depends on the selected `Source` type, detailed above
21+
Enter the value to assign to the global variable, depending on the selected type in the dropdown
3222
33-
- `Argument` - Enter the name of an existing argument to assign its value to the global variable
23+
All options support parsing of %arguments%
3424
- `Value` - Enter any value
35-
- `Increment` - Enter any `int`{lang=cs}
36-
- `Decrement` - Enter any `int`{lang=cs}
25+
- `Increment` - Enter any `int`{lang=cs} to be added to the existing value
26+
- `Decrement` - Enter any `int`{lang=cs} to be subtracted from the existing value
27+
28+
::tip
29+
If left empty, `Increment` and `Decrement` default to 1. If the global variable did not already exist, it will add or subtract from 0
30+
::
31+
3732
variables: []
3833
csharpMethods:
3934
- SetGlobalVar
4035
---
4136

37+
::warning{to=/api/sub-actions/core/globals/global-get}
38+
This **does not** also make the global variable's value available in your action<br/>
39+
To access the value of a global variable in your action, you **must *first*** assign it to a local variable with the `Get Global Variable` sub-action
40+
::
41+
4242
:read-more{to=/guide/variables}

streamerbot/3.api/1.sub-actions/core/logic/if-else.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ parameters:
88
description: |
99
The value to be tested. Performs full parsing of `%arguments%`{lang=cs}, `~persistedGlobals~`{lang=cs} and `$inlineFunctions()$`{lang=cs}
1010
::warning
11-
Unlike earlier version of Streamer.bot, arguments must be enclosed in `%...%` in order for their values to be tested. If using `Does Not Exist`, then just use the argument name, without the `%`.
11+
Unlike earlier version of Streamer.bot, arguments **must** be enclosed in `%...%` in order for their values to be tested<br/>
12+
If using `Does Not Exist`, you **must** use *only* the argument name without the `%`.
1213
::
1314
- name: Operator
1415
type: Select
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Destination
3+
type: Select
4+
default: Global
5+
required: true
6+
---
7+
8+
Select the destination type for the global variable
9+
10+
- `Global` - Set a general global variable (non user variable)
11+
- `User (redeemer)` - Set a user global for the current user who **activated** the action
12+
- `User (target)` - Set a user global for the `targetUser`
13+
- Used in conjunction with the [Get User Info for Target](/api/sub-actions/twitch/user/get-user-info-for-target) sub-action

0 commit comments

Comments
 (0)