# Class get set question

**URL:** https://discourse.processing.org/t/class-get-set-question/24087
**Category:** Beginners
**Created:** [September 24, 2020, 1:09am UTC](https://discourse.processing.org/t/class-get-set-question/24087 "2020-09-24T01:09:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pandl](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@pandl](https://discourse.processing.org/u/pandl)
#### Post date: [September 24, 2020, 1:09am UTC](https://discourse.processing.org/t/class-get-set-question/24087/1 "2020-09-24T01:09:48Z")

</div>

I’ve created an LED class that has worked well for me upto this point. Now, I have an array of leds and I need to know the state (weather it’s on or off) of a particular led. To do that I’ve added getState() to the class but the method is not correct. Say, for instance, that I have an array of leds and I want to know the state of led[3]. I can, of course, set the state with led[3].setState(true) but how to I get the state?

```auto
class Led
{
  boolean state;
  color col, onColour, offColour;
  int ledSize, xpos, ypos;

  Led(int x, int y)
  {
    xpos = x;
    ypos = y;
  }  

  void setState(boolean s)
  {
    state = s;
  }

  boolean getState(Led) // this is not correct.
  {
    return state;
  }

```

---

<div class="post-metadata">

### Author: ![raron](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/raron/32/13651_2.png) [@raron](https://discourse.processing.org/u/raron)
#### Post date: [September 24, 2020, 1:38am UTC](https://discourse.processing.org/t/class-get-set-question/24087/2 "2020-09-24T01:38:55Z")

</div>

No need to give any arguments to the get method:

```auto
Led leds[] = new Led[5];

void setup()
{
  for (int i=0; i<5; i++) {
    leds[i] = new Led(i*10, 20);
  }
  
  leds[2].setState(true);

  println(leds[2].getState());

  exit();
}

class Led
{
  boolean state;
  color col, onColour, offColour;
  int ledSize, xpos, ypos;

  Led(int x, int y)
  {
    xpos = x;
    ypos = y;
  }  

  void setState(boolean s)
  {
    state = s;
  }

  boolean getState()
  {
    return state;
  }
}

```

---

<div class="post-metadata">

### Author: ![pandl](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@pandl](https://discourse.processing.org/u/pandl)
#### Post date: [September 24, 2020, 1:48am UTC](https://discourse.processing.org/t/class-get-set-question/24087/3 "2020-09-24T01:48:00Z")

</div>

Thank you raron for your quick reply and, of course, you’re correct. I thought the error was in the class but it’s elsewhere. I should be able to track it down with the excellent debugger.
