In worst case , fly to another country from Bkk , and buy the ticket when you get into your described problem. Like a plan B or C. Prepare for that, check which near country ( and therefore cheap ticket) doesnt need a visa.
education visa. Marriage. The same way you entered till now . Get a job + workpermit and visa. Elite visa. Retirenment visa. Just google a bit the requirements and you will have more detailed questions and better answers.