2
0

docs: 📝 Improve Set variable

This commit is contained in:
Baptiste Arnaud
2022-05-16 09:13:51 -07:00
parent 98c1dea92a
commit 55224c9095
2 changed files with 26 additions and 2 deletions

View File

@ -6,6 +6,8 @@ The "Set variable" block allows you to set a particular value to a variable.
This value can be any kind of plain text but also **Javascript code**.
## Expressions with existing variables
It means you can apply operations on existing variables:
```
@ -16,14 +18,36 @@ It means you can apply operations on existing variables:
{{Score}} * {{Multiplier}}
```
## Current Date
But also set the variable to the current date for example:
```
```js
new Date()
```
## Random ID
Or a random ID:
```
```js
Math.round(Math.random() * 1000000)
```
## Current URL
A popular request also is to set a variable to the current URL. Here is the value that should be inserted:
```js
window.location.href
```
It will not give you the parent URL if you embed the bot on your site. A more bullet proof value would then be:
```js
window.location != window.parent.location
? document.referrer
: document.location.href
```
It checks whether or not the bot is embedded and return the appropriate URL.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 KiB

After

Width:  |  Height:  |  Size: 288 KiB