# Make an object variables change after interaction and change again after given amount of time

**URL:** https://discourse.processing.org/t/make-an-object-variables-change-after-interaction-and-change-again-after-given-amount-of-time/18604
**Category:** Coding Questions
**Created:** [March 11, 2020, 4:46pm UTC](https://discourse.processing.org/t/make-an-object-variables-change-after-interaction-and-change-again-after-given-amount-of-time/18604 "2020-03-11T16:46:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nadiantara](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@Nadiantara](https://discourse.processing.org/u/Nadiantara)
#### Post date: [March 11, 2020, 4:46pm UTC](https://discourse.processing.org/t/make-an-object-variables-change-after-interaction-and-change-again-after-given-amount-of-time/18604/1 "2020-03-11T16:46:40Z")

</div>

Let’s say I have two objects (b1 and b2) with different values of variables. When they are interacting, b2 has probability (let’s say 30%) to copying b1’s values. Then, after a given amount of time b2 will change its value again to default. Anyone can help me make this code works?

```auto
    int p_i = int (random(0, 100));
    if (b1.state==-1 && b2.state==0 && p_i < 30) {
      b2.state=b1.state;
      b2.cR=b1.cR;
      b2.cG=b1.cG;
      b2.cB=b1.cB;
      int TimeInfected = millis() - savedTime;
      //println(TimeInfected);
      if (TimeInfected > incubationTime) {
        b2.state=1;
        b2.cR=0;
        b2.cG=255;
        b2.cB=0;
        print(b2.cR);
        savedTime = millis();
      }
    } 

```

---

<div class="post-metadata">

### Author: ![Nadiantara](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@Nadiantara](https://discourse.processing.org/u/Nadiantara)
#### Post date: [March 11, 2020, 4:50pm UTC](https://discourse.processing.org/t/make-an-object-variables-change-after-interaction-and-change-again-after-given-amount-of-time/18604/2 "2020-03-11T16:50:20Z")

</div>

PS: the first if statement is work correctly, but the second one isn’t really working as I wish.

---

<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: [March 11, 2020, 8:22pm UTC](https://discourse.processing.org/t/make-an-object-variables-change-after-interaction-and-change-again-after-given-amount-of-time/18604/3 "2020-03-11T20:22:46Z")

</div>

> [@Nadiantara](#):
>
> if (TimeInfected \> incubationTime) {

I guess the 2nd if should be outside the first if clause?
