# Fullscreen width and height variables returning 100

**URL:** <https://discourse.processing.org/t/fullscreen-width-and-height-variables-returning-100/20351>\
**Category:** Beginners\
**Created:** [May 1, 2020, 3:14pm UTC](https://discourse.processing.org/t/fullscreen-width-and-height-variables-returning-100/20351 "2020-05-01T15:14:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kikomali2517](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kikomali2517](https://discourse.processing.org/u/kikomali2517)\
**Post date:** [May 1, 2020, 3:14pm UTC](https://discourse.processing.org/t/fullscreen-width-and-height-variables-returning-100/20351/1 "2020-05-01T15:14:49Z")

</div>

Hi! I have seen width and height returning 100 or incorrect values when a sketch is run in fullScreen() many times. Is there a way to get the accurate dimensions of the screen?

---

<div class="post-metadata">

**Author:** ![kikomali2517](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kikomali2517](https://discourse.processing.org/u/kikomali2517)\
**Post date:** [May 1, 2020, 3:25pm UTC](https://discourse.processing.org/t/fullscreen-width-and-height-variables-returning-100/20351/2 "2020-05-01T15:25:25Z")

</div>

I solved it. I’m a dumb ;D. I put a class that i got wrong width and height in outside setup and initialized it outside setup (before setup is called) so I got default values of 100

```auto
void setup(){
  fullScreen();
}

Game mygame = new Game(); // <----- A class I got the wrong values in the constructor

```

---

<div class="post-metadata">

**Author:** ![Aoyanco](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Aoyanco](https://discourse.processing.org/u/Aoyanco)\
**Post date:** [September 9, 2020, 9:26pm UTC](https://discourse.processing.org/t/fullscreen-width-and-height-variables-returning-100/20351/3 "2020-09-09T21:26:59Z")

</div>

I am having the same problem, and I don’t really understand what you’re saying. I use “width” _after_ I define the size:

```auto
void setup() {
  fullScreen();
  background(255);
}

float y=width;

void draw() {
  text(y,109,109);
//After here is just the exit button
  fill(255);
  rect(20, 20, 50, 30);
  fill(0);
  text("Exit", 30, 40);
}
void mousePressed() {
  if (mouseX >= 20 && mouseX < 70&&mouseY >= 20 && mouseY < 50) {
      exit();
    }
}
}

```

P.S. The extra code is just a “exit” button

---

<div class="post-metadata">

**Author:** ![kikomali2517](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kikomali2517](https://discourse.processing.org/u/kikomali2517)\
**Post date:** [September 10, 2020, 9:49pm UTC](https://discourse.processing.org/t/fullscreen-width-and-height-variables-returning-100/20351/4 "2020-09-10T21:49:58Z")

</div>

I am not really sure but I think the code outside of functions is executed first (Correct me if I’m wrong) then the setup then draw functions. Try putting “y = width;” at the end of setup() like here:

```auto
float y;

void setup() {
  fullScreen();
  background(255);

  y = width;
}

```

Notice the declaration of y outside of setup so It is a global variable (accessible outside of setup in this case)

---

<div class="post-metadata">

**Author:** ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)\
**Post date:** [September 11, 2020, 7:00am UTC](https://discourse.processing.org/t/fullscreen-width-and-height-variables-returning-100/20351/5 "2020-09-11T07:00:23Z")

</div>

exactly ! A variable that is declared outside a method is visible to that method, but not the other way round. All variables that are “outside” are done first, so calling on width will return its default value and size(x,y) will change these variables later.

@Aoyanco: “First” does not mean the order of lines in that case, but the hierarchy of things. You can write any variable anywhere in your code, if it is not inside a method (including) setup, it will be done before setup happens.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 12, 2020, 7:37pm UTC](https://discourse.processing.org/t/fullscreen-width-and-height-variables-returning-100/20351/6 "2020-09-12T19:37:59Z")

</div>

Variable scope:

> **[Variable Scope / Examples](https://processing.org/examples/variablescope.html)**
>
> Variables have a global or local "scope". For example, variables declared within either the setup() or draw() functions may be only used in these functions. Global variables, variables declared outsid…

[Coding Train 6.4: Variable Scope - Processing Tutorial](https://www.youtube.com/watch?v=pC7RUmHL2KY)

`:)`
