Can a plane have good range with a short take-off and landing (STOL) capability? If not, why. I have noticed STOL planes with lack the better good seat miles per gallon of planes that need longer runways. Please correct me if I am wrong.
Aircraft design is always a series of compromises. We sometimes work on it in terms of a constrained optimization problem. In this form, one thing gets to be the objective (minimum cost, or minimum weight, or maximum range) and everything else is a constraint (required takeoff distance, required payload, required speed, required range, etc.).
If you think about the space of all possible solutions - just the objective, no constraints. You have the most freedom to design. Each requirement you add removes some of the available design space. You have less freedom to design. Some requirements may be benign "the aircraft must be red" - probably won't change the maximum range solution much. Other requirements are very difficult to achieve "the aircraft must fly supersonically".
A STOL airplane is one that has been designed with more emphasis on short field performance than an otherwise similar aircraft. Because of the emphasis on STOL, a different set of compromise decisions have been made. Most likely, it adds some weight (high lift systems, rough terrain landing gear, a larger wing). Some of those changes add drag (wetted area, protuberances). The larger wing can fly slower, but it is less efficient when flying fast. These STOL additions likely affect performance in other aspects - top speed, efficiency at speed, range, payload capacity, cost.
Technology can help -- perhaps a brand new clean-sheet design can do better than a 40 year old design. However, comparing same-technology levels, the aircraft with more requirements placed on it will have to make more sacrifices in other areas.
Yes, they can. It's called retractable slats and flaps.
One plane in particular is the Fieseler Fi 156 Storch. Legendary short take off performance. Would have cruised at a much higher speed if it's slats were retractable. 400 ton airliners use them for a very enviable flight speed range of around 150 to near 600 mph. Imagine if they were a bit lighter!
In reality, building a few more feet of runway removes most STOL requirements and allows the long range cruisers to use every bit of saved weight for fuel and cargo, which will add up to a lot more $$$ over time.
But there is no reason why a smaller airplane cannot have retractable slats and flaps, except that, invariably, more weight and a larger motor with more fuel requirement makes the slightly longer runway the more popular option$^1$.
$^1$ the helicopter being another