# Why do I need the IF when using two movies

**URL:** <https://discourse.processing.org/t/why-do-i-need-the-if-when-using-two-movies/39846>\
**Category:** Libraries\
**Created:** [November 24, 2022, 10:19am UTC](https://discourse.processing.org/t/why-do-i-need-the-if-when-using-two-movies/39846 "2022-11-24T10:19:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![illus](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@illus](https://discourse.processing.org/u/illus)\
**Post date:** [November 24, 2022, 10:19am UTC](https://discourse.processing.org/t/why-do-i-need-the-if-when-using-two-movies/39846/1 "2022-11-24T10:19:00Z")

</div>

Below is a direct copy from the processing reference guide. I’m sure it will work, but I’m pretty new here, so I would like to understand why I need the if statement in the movieEvent.  
Basically why can’t this be just m.read() instead of the construct with the if.

trying to learn something 😉

```auto
import processing.video.*;

Movie myMovie, yourMovie;

void setup() {
  size(200, 200);
  myMovie = new Movie(this, "totoro.mov");
  yourMovie = new Movie(this, "catbus.mov");
  myMovie.play();
  yourMovie.play();
}

void draw() {
  image(myMovie, 0, 0);
  image(yourMovie, 100, 0);  
}

void movieEvent(Movie m) {
  if (m == myMovie) {
    myMovie.read();
  } else if (m == yourMovie) {
    yourMovie.read();
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 24, 2022, 10:23am UTC](https://discourse.processing.org/t/why-do-i-need-the-if-when-using-two-movies/39846/2 "2022-11-24T10:23:15Z")

</div>

In this case two movies are handled

When you only have one movie, you don’t need the if

The if has the purpose that we distinguish between the two movies since they share the same function here

---

<div class="post-metadata">

**Author:** ![illus](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@illus](https://discourse.processing.org/u/illus)\
**Post date:** [November 24, 2022, 10:28am UTC](https://discourse.processing.org/t/why-do-i-need-the-if-when-using-two-movies/39846/3 "2022-11-24T10:28:36Z")

</div>

but if the Movie m is a parameter to the movieEvent(), doesn’t it point to the movie that triggered the event?  
It feels odd to me that I can do  
`if (m == myMovie) { myMovie.read(); }`  
but  
`if (m == myMovie) { m.read(); }`  
would be bad. and if it isn’t bad why can’t I just do m.read()

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 24, 2022, 11:15am UTC](https://discourse.processing.org/t/why-do-i-need-the-if-when-using-two-movies/39846/4 "2022-11-24T11:15:15Z")

</div>

Good point

Definitely worth a try

---

<div class="post-metadata">

**Author:** ![illus](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@illus](https://discourse.processing.org/u/illus)\
**Post date:** [November 24, 2022, 11:27am UTC](https://discourse.processing.org/t/why-do-i-need-the-if-when-using-two-movies/39846/5 "2022-11-24T11:27:05Z")

</div>

it works just fine without the IF, but I’m trying to understand why the reference manual makes an explicit point of it to do it with the IF statement. It’s probably more a java question than a processing one, but i would like to understand it.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 24, 2022, 4:49pm UTC](https://discourse.processing.org/t/why-do-i-need-the-if-when-using-two-movies/39846/6 "2022-11-24T16:49:37Z")

</div>

Hi @illus,

Guess it is only for demonstration purpose, if you need to know which movie triggers the event.  
You can simply use m.read() if you are not interested on the latter…  
As the several movie objects triggering the same event (method name) you’ll get the correct frame for each movie…

Cheers  
— mnse
