2
0
Files
bot/apps/docs/editor/blocks/logic/script.mdx

38 lines
979 B
Plaintext
Raw Normal View History

---
title: Script block
icon: code
---
2022-05-17 13:48:56 -07:00
2023-07-16 09:41:35 +02:00
The "Script" block allows you to execute Javascript code. If you want to set a variable value with Javascript, use the [Set variable block](./set-variable) instead. You can't set a variable with the script block.
2022-05-17 13:48:56 -07:00
2022-06-17 08:04:22 +02:00
**It doesn't allow you to create a custom visual block**
2022-05-17 13:48:56 -07:00
<Frame>
<img src="/images/blocks/logic/code.png" width="600" alt="Code block" />
</Frame>
2022-05-17 13:48:56 -07:00
<Info>
Variables in script are not parsed, they are evaluated. So it should be treated as if it were real javascript variables.
You need to write `console.log({{My variable}})` instead of `console.log("{{My variable}}")`
</Info>
2022-05-17 13:48:56 -07:00
## Examples
### Reload page
```js
window.location.reload()
```
### Redirect if a variable has a specific value
2022-05-17 13:48:56 -07:00
```js
if({{Category}} === 'qualified') {
window.location.href = 'https://my-site.com'
}
2022-05-17 13:48:56 -07:00
```
Do you need to do something but you're not sure how to? [Join the Discord server](https://typebot.io/discord) and get instant help!