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

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?

    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();
      }
    } 
1 Like

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

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

1 Like