Switch
![if](http://lf16-tiktok-common.tiktokcdn-us.com/obj/tiktok-web-common-tx/effect/learn/assets/images/switch-cde20d481a2c35c707a9261c5b358e53.png)
Use Switch to take different executions according to the input index. You can add click the "+" to add more outputs. Switch is in the Control category.
Input
Name | Data Type | Description |
---|---|---|
Enter | Trigger | The input execution that triggers this node. |
Input | Number | The input rounded value, controlling which execution to be taken. For example, if the input is 1.4, it will be rounded to 1; if it is 1.5, it will be rounded to 2. |
Output
Name | Data Type | Description |
---|---|---|
0 | Exec | Execute the next node when the input index is 0. |
1 | Exec | Execute the next node when the input index is 1. |
2 | Exec | Execute the next node when the input index is 2. |
Example
![switch example](http://lf16-tiktok-common.tiktokcdn-us.com/obj/tiktok-web-common-tx/effect/learn/assets/images/switch_example-326ce728391161fff6e096121a34eb4e.gif)
This example demonstrates an effect where tapping the screen will randomize the icon that appears on the screen. It generates a random number and corresponds each number to a texture for the 2D image. When you tap on the screen, it will trigger the switch.
tip
The default number of output ports is 3. Click the “+” button at the bottom right corner to add more ports.
![switch node](http://lf16-tiktok-common.tiktokcdn-us.com/obj/tiktok-web-common-tx/effect/learn/assets/images/switch_node-ac9de686b573f18ac51a1fa10b37e2bb.png)