# Switch between floors in house layout by clicking button

**URL:** https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475
**Category:** Coding Questions
**Created:** [June 3, 2021, 2:08pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475 "2021-06-03T14:08:33Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![lightbombs](https://avatars.discourse-cdn.com/v4/letter/l/9dc877/32.png) [@lightbombs](https://discourse.processing.org/u/lightbombs)
#### Post date: [June 3, 2021, 2:08pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/1 "2021-06-03T14:08:33Z")

</div>

This is the house layout of ground floor and first floor, the lights, radiators and windows turn on and off by clicking on them.

What i want to do is, when i click top left the OG button it will show the first floor and when i click the EG button it shows the ground floor but i dont know how can i do that?

currently each floor is in a seperate .pde file

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/24f9c245fc86ef8b47d592a55c1ba9ff1626d524.png)

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [June 3, 2021, 5:06pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/2 "2021-06-03T17:06:10Z")

</div>

Hello @lightbombs  
If both floors are moved into a single pde It seems you could do this via a Boolean. If true, draw floor one to the screen, and if false, draw floor two to screen. Perhaps? And as you stated the OG / EG buttons are your target area to initiate on\off or true/false.  
🤓

---

<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: [June 3, 2021, 5:43pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/3 "2021-06-03T17:43:21Z")

</div>

Very good answer here!

`boolean drawFloorOne = true;`

**Remark**

But is your Switch “All Windows Open” referring to the current floor or to both floors?

When it’s referring to the current floor only:

- When you have variables for the windows, heating and lights and you join the two pde-files to one Sketch (two tabs) make sure you name e.g. the lights like floor1Light0, floor1Light1 etc.

Then evaluate drawFloorOne not only in draw() but also in the mousePressed() function

```auto
if(drawFloorOne) {
   // check switches for floor 1
   floor1Light0=....
} else 
{
   // check switches for floor 2
   floor2Light0=....
}

```

Chrisir

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [June 3, 2021, 5:48pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/4 "2021-06-03T17:48:55Z")

</div>

changed the topic category as it seems its in Processing (java) not p5.js 🙂

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [June 3, 2021, 5:54pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/5 "2021-06-03T17:54:21Z")

</div>

@micuat Since no code shown in original post, how can you tell if in p5js or processing?  
Just wondering…  
🤓

EDIT: oh never mind, it must be the .pde, 🙂

---

<div class="post-metadata">

### Author: ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)
#### Post date: [June 3, 2021, 7:23pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/6 "2021-06-03T19:23:13Z")

</div>

That’s a way but maybe you want to add more floors later. If that’s the case you could use an Enum.

Here an Example:

```auto
//you dont have to have the enum name in capital letters
FLOOR currFloor;

void setup() {
  size(600, 600);
  currFloor = FLOOR.EG;//or FLOOR.OG
}
void draw() {
  if (currFloor == FLOOR.EG) {
    //EG stuff
  } else if (currFloor == FLOOR.OG) {
    //OG stuff
  }
}
enum FLOOR {
  EG, 
    OG
};

```

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [June 3, 2021, 9:53pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/7 "2021-06-03T21:53:36Z")

</div>

Can you please elaborate? I don’t understand how additional floors can be pointed to. There is need of additional code to do this? I don’t have a JAVA background so any clarification is most appreciated. I did google and YouTube about enums but info did not completely translate to usage in your example…  
🤓

---

<div class="post-metadata">

### Author: ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)
#### Post date: [June 3, 2021, 11:00pm UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/8 "2021-06-03T23:00:29Z")

</div>

Im not sure what you mean, but you can imagine that an enum is like a class, only that it has no cunstructure and cannot “store” integers or strings.

For Example:

```auto
class myClass {
  //The class can "save" some intergers or Strings
  int myInt;
  String myString;
  float myFloat;
  PVector myPVector;//You know what I mean
  myClass() {
    //This is the cunstructure I think (im not sure because i am from germany) sry
  }
}
//Enum:
enum myEnum {
  Hello, 
    Enum, 
    OrSomethingLike, 
    That
}

//now we can create a variable

myClass myWonderfullClass;
myEnum myWonderfullEnum;

//You have to have a setup function otherwise you will get an error...
void setup() {
  //You have to initialize the class I think im not sure 
  myWonderfullClass = new myClass();

  //Enum:
  //myWonderfullEnum = the "class" type of the variable in my case: myEnum
  //and than a point so that you can get "access" to the type for Example : Hello or Enum or OrSomethingLike or That
  myWonderfullEnum = myEnum.Hello;
  //in the class its similar when you want to access a variable you can say thr name of the class in my case:
  //myWonderfullClass then a point and than the variable name so:
  //myWonderfullClass.myInt = 5;
}

```

I hope i could help you  
😁

Flolo

Edit:  
If you want (for Java generall) to do more with enums try this out:  
[Enum Types](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html)

---

<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: [June 4, 2021, 7:26am UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/9 "2021-06-04T07:26:08Z")

</div>

A boolean distinguishes between 2 floors.

If you had more than 2 floors, you could use an int variable with can be 0,1,2… to indicate many floors. (Of course you still have to make these floors)

enum is now a way to tell the int which numbers it can hold so we can’t use any others (enumerated)

- by the way using an int to indicate a floor is similar to the concept of state / screen often seen here in the forum

Chrisir

---

<div class="post-metadata">

### Author: ![lightbombs](https://avatars.discourse-cdn.com/v4/letter/l/9dc877/32.png) [@lightbombs](https://discourse.processing.org/u/lightbombs)
#### Post date: [June 4, 2021, 9:00am UTC](https://discourse.processing.org/t/switch-between-floors-in-house-layout-by-clicking-button/30475/10 "2021-06-04T09:00:18Z")

</div>

Thank you everyone for the help, i really appreciate it
