This is a post about my recently completed Choose Your Own Adventure game. It was a really small program, only about 500 lines, but it was my first program that was fully functional, first program that I compiled to .exe and shared, and first one that used a few different tkinter modules. I’m going to write about what I really enjoyed doing, and what I didn’t, as well as the features, and what I plan on doing with my CYOA program in the future.
Firstly, the feature list is small, but simple:
- A custom file parser that looks for the tags for page name, text, and choices for where you want the story to go next
- Dynamic pages loaded from the story file that anyone can create and load.
- Scrollbars. I added this because what list only has two items. There is scrollbars on the history frame that tracks which pages you’ve been to, and you can go to any one of them on the fly.
So anyways, what I enjoyed doing was mainly completing the project. It didn’t take very long, just a week or two of good effort, but seeing it spit out the text that we had put into the custom file there was really nice. I realized that that was the best part of programming, seeing the application behave, or do something, that you didn’t explicitly program. Seeing it successfully run through a story makes me want to try to tackle harder challenges.
I’m proud of the way it loads up each page from the file you load into it, so you can write any story you want, so long as the file follows the following template:
~[page_name= First page~]
~[sheets_out= SecondPage, ThirdPage, FourthPage~]
So, you put in a page name, the story text and the title of the next pages that you want to load up next. There’s an extraneous ‘sheets_in’ which could be used in a later feature, but right now, it is unused. There’s also the PAGE_START and PAGE_END tags which separate each page for the parser.It’s simple, and I find it to be clean and at least decently efficient even though I haven’t tried it with a story with more than 20 or so pages.
The way each page is created independently of each other, so you can jump to any given page that you’ve already navigated to, using the history bar on the side of the text. That was my first time using the listbox and scrollbar tk widget. I was surprised to learn that the scrollbar doesn’t overlay on the widget, but is actually in the adjacent column as close as possible.
I used regex on the text file with the story, but that was really tough to get right, due to my inexperience with it. Luckily I had RegExr’s help with it, followed by the Online Python Regex Tool to try the regex in actual code. Regex is definitely powerful, but its syntax is one of the least readable things for a newbie like me. Still though, I’m sure with time it’ll be easier and easier. It was probably the least fun I had with the entire program, because sometimes I was unable to understand why it would work with some strings, and not with other similar ones.
Another tool I used for the first time was Py2exe and another similar tool. I tried to use py2exe and it didn’t even run on my pc, but I’m willing to chalk that up to my vast inexperience once again. I was told over reddit in a thread I had created asking about this very thing about the best way to do this, and I was introduced to pyInstaller, which puts everything you need into one exe that you can distribute without installing any other libraries, but when I tested it on a computer without Tcl, it crashed almost immediately. Still not sure why py2installer doesn’t include that.
Finally, I am considering expanding the tool and make it a public application that anyone can use. I’m not sure there’s a big demand for it, but I feel like I can find a subreddit that would definitely be able to find a use for it. In the very least a more capable programmer would be able to turn it into something a bit more usable.
Anyways this is longer and I’m too tired to proofread it, so might as well stop here. Til next time!