# Problem with setup() loading order, instantiate an object with 'width' and 'height'

**URL:** <https://discourse.processing.org/t/problem-with-setup-loading-order-instantiate-an-object-with-width-and-height/14552>\
**Category:** Beginners\
**Created:** [October 9, 2019, 3:02pm UTC](https://discourse.processing.org/t/problem-with-setup-loading-order-instantiate-an-object-with-width-and-height/14552 "2019-10-09T15:02:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Protos](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@Protos](https://discourse.processing.org/u/Protos)\
**Post date:** [October 9, 2019, 3:02pm UTC](https://discourse.processing.org/t/problem-with-setup-loading-order-instantiate-an-object-with-width-and-height/14552/1 "2019-10-09T15:02:57Z")

</div>

Hi,  
How can I reliably provide `width` and `height` to the constructor while creating an object instance.  
I am constructing a “device object” from a class which is automatically loaded before setup() is executed. In the device constructor I am using width and height as a reference to the device about the screen size. Since setup() is not yet processed at this point, width and height read as 100.0. So this doesn’t work.

I can’t use globals in setup. What would be a normal solution for this problem.

Here some example code:  
In my root file:

```auto
void setup() {
  size(1600, 1200);
}
Device myDevice = new Device(width, height);

```

in my device class (different tab/file)

```auto
class Device{
  int objWidth;
  int objHeight;
  int screenWidth;
  int screenHeight;
 
 Device(int sW, int sH){
   objWidth = 300;
   objHeight = 60;
   screenWidth = sW;
   screenHeight = sH;
   position.y = screenHeight / 2;
   position.x = 0;
 }
}

```

If not clear enough, please let ne know

Cheers,  
Stowoda

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 9, 2019, 3:07pm UTC](https://discourse.processing.org/t/problem-with-setup-loading-order-instantiate-an-object-with-width-and-height/14552/2 "2019-10-09T15:07:16Z")

</div>

> [@Protos](#):
>
> What would be a normal solution for this problem.

```auto
Device myDevice;

void setup() {
  size(1600, 1200);
  myDevice = new Device(width, height);
}

```

---

<div class="post-metadata">

**Author:** ![Protos](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@Protos](https://discourse.processing.org/u/Protos)\
**Post date:** [October 9, 2019, 3:18pm UTC](https://discourse.processing.org/t/problem-with-setup-loading-order-instantiate-an-object-with-width-and-height/14552/3 "2019-10-09T15:18:41Z")

</div>

Ah, alright, thank you! I had the type Device inside the setup().  
Chapeau!

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [October 9, 2019, 11:55pm UTC](https://discourse.processing.org/t/problem-with-setup-loading-order-instantiate-an-object-with-width-and-height/14552/4 "2019-10-09T23:55:04Z")

</div>

If you want to use global vars to set width and height use

```auto
settings(){
  size(int1, int2);
}

```

Outside of setup.

---

<div class="post-metadata">

**Author:** ![Protos](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@Protos](https://discourse.processing.org/u/Protos)\
**Post date:** [October 10, 2019, 8:01am UTC](https://discourse.processing.org/t/problem-with-setup-loading-order-instantiate-an-object-with-width-and-height/14552/5 "2019-10-10T08:01:53Z")

</div>

Thank you for this insight. This is very helpful.
