How to prevent myself from yoyo dieting

Options
About a year ago, I started working out because I was in a really bad shape. I started seeing a huge progress in my weight loss. A couple of months later, stopped saying any progress on the scale and when I would look at myself on the mirror. It somewhat demotivated me from working out hard so I completely slowed down my progress until eventually I stopped. The 20 pounds that I lost immediately caught up to me in a matter of 2-3 months. I am being called fat by my family members (even they are just joking), I cant wear size 34 anymore, my Gut sticks out when I wear a shirt and my pecs are not looking too pretty. Based on the research that I made, I figured out why my weight loss was such a failure.

Based on that knowledge, I know I can get back on track and maintain a healthy weight. I am not looking to get shredded or insanely toned ATM. I just want to increase my metabolism, eat right and feel comfortable being around people.

I think the lack of exercise was one of the reasons why I gained so much weight. The other part was that I would just eat as unhealthy as possible because I would be under the assumption that if I'm not working out, there is no reason for me to eat healthy.

Point being is that I do not want myself to have to go through something like this again. I just don't want to get in good shape and lose motivation and gain all that weight back that I lost. It seriously demotivates you to go back in the gym and work out again.