# Cannot invoke red() on the primitive type int

**URL:** <https://discourse.processing.org/t/cannot-invoke-red-on-the-primitive-type-int/39575>\
**Category:** Beginners\
**Created:** [November 3, 2022, 7:33pm UTC](https://discourse.processing.org/t/cannot-invoke-red-on-the-primitive-type-int/39575 "2022-11-03T19:33:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanto2016](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nanto2016](https://discourse.processing.org/u/nanto2016)\
**Post date:** [November 3, 2022, 7:33pm UTC](https://discourse.processing.org/t/cannot-invoke-red-on-the-primitive-type-int/39575/1 "2022-11-03T19:33:19Z")

</div>

Hello, I here have a problem I do not understand: the code below prints to the console : `Cannot invoke red() on the primitive type int`

```auto
void mousePressed() {
  color m = get(mouseX, mouseY);
  if(m.red() == 255 && m.green() >= 200)
    clicked();
}

```

There are absolutely no integers involved here, `m` is of type `color`, not `int` !  
Thanks to anyone who can help me, this is very confusing.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [November 3, 2022, 7:39pm UTC](https://discourse.processing.org/t/cannot-invoke-red-on-the-primitive-type-int/39575/2 "2022-11-03T19:39:38Z")

</div>

A `color` is secretly an `int`. This fact is hidden from most casual users.

The red() function is not called on a color. Instead, pass the color to the function:

`if(red(m) == 255){`

---

<div class="post-metadata">

**Author:** ![nanto2016](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nanto2016](https://discourse.processing.org/u/nanto2016)\
**Post date:** [November 3, 2022, 7:41pm UTC](https://discourse.processing.org/t/cannot-invoke-red-on-the-primitive-type-int/39575/3 "2022-11-03T19:41:44Z")

</div>

Oh… Once again, I found my own answer right after posting: replacing `red` and `green` by `>> 16 & 0xFF` and `>> 8 & 0xFF` (which is something proposed on the reference for `red()`) solved the problem! I don’t understand what was the issue in the code I first wrote but here I have my correct results.

---

<div class="post-metadata">

**Author:** ![nanto2016](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nanto2016](https://discourse.processing.org/u/nanto2016)\
**Post date:** [November 3, 2022, 7:47pm UTC](https://discourse.processing.org/t/cannot-invoke-red-on-the-primitive-type-int/39575/4 "2022-11-03T19:47:47Z")

</div>

Oh thanks, I had forgotten about that… 🤦  
And wow, I actually tested out the `color` / `int` thing and it just works: you can replace `color` by `int`, well at least in my case. That is very interesting!
