Automatic Flashlight Activation Help

So I am attempting to have a flashlight automatically turn on when the light sensor detects a value lower than a set one. I can’t seem to get it to work. Am I doing something wrong. Also, I had tried to make an auto-calibration system, which would detect a light value with a button press (Btn6U), then turn on the flashlight when the sensor detected a lower value. If someone knows a method to do that as well, that would be helpful.
Here is the code snippet I have for my light sensor:
int roomlight=150;

task main()
//!!Below is expirmental !!//
if (roomlight>SensorValue(lightsensor))
//!!Above is expirmental !!//