code: function onchange(chg) {
  		if(robot.data.mode == 3 && run == 1) { //FULL mode:
  			//lightBumper is a macro for all light bump sensors (lightBumpLeft, lightBumpRight, etc)
  			//Unfortunately, no similar macro exists for cliff sensors or bumper switches due to the way the data is delivered.
  			if(chg.lightBumper || chg.bumpLeft || chg.bumpRight || chg.dropLeft || chg.dropRight || chg.clean || chg.docked) {
  				driveLogic(); //Run drive logic only when sensor values change.
  			}
  			//Charging Station Detected! Since it's in front of the robot anyway... Start Auto-Docking!
  			if(robot.data.irLeft == 172 || robot.data.irRight == 172) {
  				robot.drive(0,0); run = -1; robot.showText("SEEK", 500, false, robot.autoDock);
  			}
  		} else if(robot.data.mode == 1) { //PASSIVE mode:
  			if(chg.clean && robot.data.clean) { //Clean Pressed:
  				if(robot.data.docked) robot.clean(); //Start backing up if clean pressed while docked.
  				else preventDefault(function(){run = 1; driveLogic()}); //Prevent default.
  			}
  			if(chg.docked && robot.data.docked) { //Robot Docked:
  				setUndock(0); robot.full(); robot.showText("DOCK", 500, false, robot.start);
  			} else if(chg.docked/* && !robot.data.charger*/ && !robot.data.docked) { //Robot Undocked:
  				setUndock(1);
  			} else if(chg.dropLeft || chg.dropRight) { //Docking Interrupted:
  				if(run == -1) {robot.full();robot.showText("RST", 500, false, robot.autoDock)}
  				//else setUndock(1);
  			}
  		}
  	}
docs: Handle onChange Events: