Building Narrative CLI programs using an API — or how I stole Rick’s watch

christopher diercksen
2 min readMar 21, 2021

To the observer, any sequence of events serve as the plot to their personal narrative. These are the building blocks of stories: something happened, followed by another something, which means something else. It is through this lens that I approached building my CLI program, Ricks_Watch.

The premise is simple: the user tries on super-genius Rick Sanchez’s watch, not realizing it will suck them through a wormhole to a distant location.

“Greetings, Rick Sanchez, where would you like to go?”

Thanks to the wonderful resource, Rick & Morty API, I had access to a nested hash of information about locations and characters from the Rick & Morty narrative universe. Crucially, this information included relationships between locations and characters: locations provided a list of residents; characters provided not only their current location (or where they reside) but also their location of origin.

I created a Location class that would instantiate with a name, url, and list of residents using parsed information from the API before collecting in a class variable array(@@all). I then presented those locations with an index number to the user.

“Please select a number to travel to that location”

Once a location is selected, it’s saved to a class variable for future use. As for the user…

“DNA Match: Not Found. Initializing Wormhole.”

…they’re shunted through a wormhole and “arrive” at their selected location, receiving a cheerful congratulations for surviving the trip from Ricks Watch. The user is then given the option to either call Rick for help (he’s busy) or talk to local residents to see if they’ll send you home.

Building this menu from a narrative perspective was particularly fun. Residents will not talk to you until you check in with Rick, who threatens them if they don’t offer assistance. I relied primarily on if/else conditions and counters to make that work. Location instances designate their residents by url, which I parsed to instantiate new instances of my Character class. Those instances were collected in a class variable array so I could more easily present them as an indexed menu for the user.

“Please input the number of the resident you would like to speak to”

The resident then sends you through another wormhole and you’re back in Rick’s Garage.

This program has a super simple functionality to it at the moment but I am continuing to build it out to provide more fail states. Ideally, I would like to make it so that residents send you not straight home, but to their location of origin. The goal would be to have the user location-hop around the Rick & Morty universe with a limited amount of jumps available to them. Should the user happen to arrive back on Earth, the user wins.

--

--

christopher diercksen
0 Followers

Theater Director, Dramaturg, Producer, Improvisor, Artistic Director, Office Manager, Software Engineering Student. (He/They)