Search code examples
simulationanylogic

Object should change color after 2 second, when agent enterers in "delay" Block


When agent enters in block the Object (rectangle) changes color instantly. What I want is when agent enters in block object (rectangle) it should take 1 or 2 seconds to change its color.

My Approach

  • Make a boolean variable called "temperature".
  • on "On enter" of Delay block temperature = true
  • on "On exit" of Delay block temperature = false
  • In object (rectangle) "Fill Color" is temperature == true ? red: brown

Solution

  • Use a Dynamic Event, name it myDE. Give it 1 argument myAgent of type YourAgentType. In the action code, you write myAgent.myRectangle.setFillColor(yourColor);

    In the "on enter" code of the delay block, you create the event using create_myDE(2, SECOND, agent)

    Now every agent arriving in the delay will schedule an event 2 sec after entering that will change that agent's rectangle.