GLaDOS – Interactive Portal 2 credits console

Last year I played through the Portal games again. When I finally beat Wheatley, I felt both happiness and sadness. The games were over, no GLaDOS for me anymore.

Though it didn’t end like that. When seeing the credits screen, I had an idea. Wouldn’t it be fun to build the credits screen from Portal 2 as an actually working website? Yes, it would, so I did it.

I’m not a big fan of JS, but to keep it interactive and fun, I had to implement everything on the frontend. I wrote some basic CSS to layout everything like it’s seen on the game, and started to blow some life into it by writing a batch of basic functions that I can later use to write small programs: print() and println() for printing stuff on the console, throwerror() to notify the user about a mistake on his end (with a snarky GLaDOS quote) as well as oc() and cc() as a semaphore for locking the console. That and some way to start the programs was enough to start writing some small and fun programs.

I began with writing the reddit program. Because of Cluffle I already had enough knowledge about the reddit API to easily implement this feature. Quickly enough I could enter “reddit webdev 20”, and the page would kick out an AJAX call to my server, where a short PHP script would proxy the request to reddit. Et voil√†, the first program was finished.

The second one was 4chan. I searched around for interesting APIs, and as I sometimes browse /diy/, I decided to add it as an fun and SFW way to browse 4chan. A few AJAX calls later to my proxy script, and I could actually use it.

The third one was Google. I didn’t even know that Google had an API for searches, but a bit of googling around proved me otherwise. So I added it as a short program and could proxy Google searches. Google is the only part where the proxy is actually interesting: After I posted this page on reddit (~450 points on /r/internetisbeautiful), I got so many requests that Google cut down my API access. So I disabled that feature while the page was on top of /r/internetisbeautiful and later reenabled it when the traffic fell down again. IIRC some dude later used the page to proxy Google because Google was blocked in his country.

The most interesting feature though has to be the command ‘wantyougone’: It emulates the credits scene from the game, including the song and console output. I actually downloaded a video of the credits and used some video editing software to get the exact timespans to print the lines of text in the exact same time as in the game. It turned out really well, but Chrome messed up the timeouts for the text when switching the tab.

Anyways, the whole several minutes song caused another inconvenience: I couldn’t cancel the programs once they ran. That wasn’t a problem for the reddit or Google APIs, but the song blocked the console for a long time. So I decided to add the known CTRL+C. That button-combo cancels the running process as one is used from consoles. The solution is actually pretty simple: Just register a cleanup function for every program, if necessary, and run it once the abort signal comes. For wantyougone it simply kills all the timeouts, stops the music and unlocks the console. Easy as that.

Other than that I added some small programs to make the system more convenient, including up and down arrows for accessing previous commands as well as a way to print a help screen and clear the console.

The observant user may have noticed the three zeros on the top left corner. I used them to indicate the current temperature, humidity and dew point of my flat by accessing that data from my smarthome system. Unfortunately though, I ended up DOSing myself that way: A ton of redditors (by far not as many as at Cluffle though), and a refresh interval of a few seconds, times three requests equals to a ton of requests on my smarthome. Since about a year now I’m in the process of rewriting said smarthome, but until I’m finished with that these number will stay at 0.

GLaDOS was another project I consider highly successful. It got quite some attention on and positive feedback from reddit, was written in clear and working code and is still online, ready to be used. Its code is accessible on Github.