Distance gets you the x, and the y, offset gets you the x, or the y.
You should just use one for your detection.
Also the way you have it set up your saying if the distance is greater than 300, or the distance is less than 300 then move, but that will make the troll move all the time, and distance() doesn't care if the player is to the left or to the right.