The long term trick is to learn limitations no matter the situation.
So; you fell off the wagon, there was a consequence - weight gain and with it recognizing that all the previous weeks hard work was for nought.
Getting back on that wagon immediately rather than after another meal, another day, another weekend or week is that trick.
You can do this!