Funtimes is offline now because bat2web is not good enough. I designed it to work on the terminal first, and making it work on the web was an afterthought. Also, I knew less about Flask when I made it (which is why you can't save the game into a cookie yet).
When requesting input from the user, as a quick hack to make it work online, bat2web enters a while loop and continuously checks if user input is in a queue that gets filled by another thread. It's bad, but it works... kinda. I'll call it a proof of concept. 😛
There's two methods I've thought of to improve the program. One method would be a better system for separating these threads into different processes, keeping them alive as we do now, and managing them at a higher level. That sounds annoying, although it would be cool.
Another method (which I'm more inclined to do) would be to make Batchfile.py's state serializable so that the Python process can be started fresh with each network connection.
I think I can re-enter an arbitrary part of a batchfile chain if I store the callstack with line-numbers and the currently defined variables. I think it would work? 🤔 Perhaps not for all batchfiles, but it should work for Funtimes.bat
The server would receive the callstack as a list of dictionaries, and the variables as a dictionary. Create a new Python process with Batchfile.py, then define the variables and jump to the line-number belonging to the last member of the callstack list. If an exit must be performed, pop the last item from the callstack and go to the line-number above it. When the callstack is empty, exit the program.
Not sure if I'm going to program this or if it would actually work, but it's an idea.
#blog #batchfile #python