# Using width outside main file

**URL:** <https://discourse.processing.org/t/using-width-outside-main-file/14659>\
**Category:** Coding Questions\
**Created:** [October 13, 2019, 4:05pm UTC](https://discourse.processing.org/t/using-width-outside-main-file/14659 "2019-10-13T16:05:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dVaGaymer](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@dVaGaymer](https://discourse.processing.org/u/dVaGaymer)\
**Post date:** [October 13, 2019, 4:05pm UTC](https://discourse.processing.org/t/using-width-outside-main-file/14659/1 "2019-10-13T16:05:44Z")

</div>

I’m starting here, trying to program a simple pong, but there is a problem when I change the value of initial Player object position.  
I want to give the object (a racket) an initial position based on the window’s size, like y = width/2  
But since I did not use size(); in this class Player the program uses this width as 100.  
How can I fix this?  
Do I have to give the size of the window as parameter? It doesn’t sound efficient.

---

<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:** [October 13, 2019, 4:20pm UTC](https://discourse.processing.org/t/using-width-outside-main-file/14659/2 "2019-10-13T16:20:34Z")

</div>

Maybe you want to show your code here

but in general:

When you have a function setup() (which you should have), size() should be the first command in it.

All use of width and height would work only AFTER size().

This means you can‘t say `y=width` before setup or before size

Instead before setup say float y; (making y a global variable) and inside setup but after size say y=width; without float.

Also you can’t instantiate an object with new before setup or size when the constructor makes use of width or height.

**Apart from this:** you should never use width etc as a variable name. Instead say widthPaddle or so

---

<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:** [October 13, 2019, 4:23pm UTC](https://discourse.processing.org/t/using-width-outside-main-file/14659/3 "2019-10-13T16:23:46Z")

</div>

> [@dVaGaymer](#):
>
> did not use size(); in this class Player

You can use size only once in setup and never in a class.

width is known in all classes unless you make a variable of the same name which you should not do
