# Interactive Video with Audience Options

**URL:** <https://discourse.processing.org/t/interactive-video-with-audience-options/16805>\
**Category:** Project Guidance\
**Created:** [January 2, 2020, 11:18am UTC](https://discourse.processing.org/t/interactive-video-with-audience-options/16805 "2020-01-02T11:18:17Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [January 8, 2020, 10:42pm UTC](https://discourse.processing.org/t/interactive-video-with-audience-options/16805/6 "2020-01-08T22:42:40Z")

</div>

Another useful concept for these kinds of projects is “state machine”

[https://discourse.processing.org/search?q=state%20machine](https://discourse.processing.org/search?q=state%20machine)

So you have states like this:

```auto
int s0video = 0;
int s0choice = 1;
int s1video = 2;
int s1choice = 3;
int s2video = 4;
int s2choice = 5;
int s3video = 6; 
//....
int current = s0video;

```

and then you have rules like “if the state is s2choice and the mouse clicks on the right hand side of the screen, the state is now s5video”:

```auto
if(current==s2choice && mousePressed && mouseX>width/2) {
  current==s5video;
}

```

Draw to the screen displaying the video or buttons based on whatever the current state is.

For previous discussion of sketch state in a simple interactive experience, also see:

> [@How to make keyPressed work inside a while loop](https://discourse.processing.org/t/how-to-make-keypressed-work-inside-a-while-loop/3257/8):
>
> This is the key thing to understand. Processing is already designed to make things like this easy if you treat draw like your while loop. After the end of every draw (every frame), all the interaction functions – mouseDragged(), keyPressed(), keyReleased(), etc. – are checked. So I recommend following @jb4x’s advice and do your checking there. If you have a lot of different states, then write a simple state machine by turning most of your draw loop into a switch statement. [Reference / Proce…](https://processing.org/reference/switch.html)

---

_[View the full topic](https://discourse.processing.org/t/interactive-video-with-audience-options/16805)._
