SPOILER WARNING! This interview is about the plot, characters and script of Portal 2, so it necessarily contains spoilers right through to the game's ending. You should wait until you've completed the game to read it (which is why we've held publication back until today).

Erik Wolpaw looks tired. The mousy, bespectacled writer has a cracked voice and a bad cold. He seems nonplussed because, at the time of this interview in Valve's offices overlooking a typically drizzly Bellevue, Washington, he finished work on Portal 2 four weeks ago, yet there's still four weeks to go until its release. He's in limbo.

Hopefully he feels better now, because his game is out in the wild, being loved by players and showered in praise by critics – including me, in our 10/10 Portal 2 review.

As its scriptwriter, along with National Lampoon veteran Jay Pinkerton and his former collaborator on the Old Man Murray website, Chet Faliszek, Wolpaw's contribution to its brilliance and success is not small. "It's both shameless and devastatingly successful in its pursuit of belly laughs," I wrote. "Portal was a sequence of great jokes, but Portal 2 is that rare beast, an actual video game comedy – and one of the funniest ever."

It's an even greater achievement when you consider that Portal 2 manages this with no 'actors' on the screen. Wolpaw and Pinkerton (Faliszek came on later and mostly contributed lines to the co-op campaign) successfully conjure characters from voices that are either idiotic, psychopathic machines or recorded ghosts from the distant past – and in doing so, they expand the icy skit of the original Portal into both a human drama and a compelling action yarn.

So I'm eager to ask Wolpaw (who, before joining Valve as a writer, contributed to the script for Double Fine's brilliant Psychonauts) how they pulled it off. Remember: spoilers!

Eurogamer: Are you happy with Portal 2?

Erik Wolpaw: Oh yeah. From a writing perspective, it's this ongoing process here – because we're embedded with the game teams, so it's not like you're writing a script and you hand it off to somebody two years ago and hope that everything turns out alright in the end.

You're there all the way to the end, both in good and bad ways. You can kinda make sure that things are the way you want them by the time it comes out. So if it comes out and everybody hates it, I don't have anyone to blame from a writing perspective but me. I can't say anybody screwed anything up.

Video: Here are your test results: you are a horrible person. (Video: first 15 minutes of Portal 2.)

Eurogamer: I guess it was quite a challenge, because you had to expand the universe and expand what was a very tight little idea in the first game, with GLaDOS' comments in between the test chambers.

Erik Wolpaw: Yeah, so we knew it was going to be a bigger game – although having said that, the thing we tried to hang onto from the writing perspective was that we didn't want to make this galaxy-spanning cast-of-thousands sort of sequel. The goal was to still make it feel relatively intimate as video game stories go – it's still about this relationship between you and GLaDOS, and then how that relationship gets complicated by these various other characters.

Because, to me, that's something about Portal 1 – it just felt like a small-scale story. Video games tend to go really broad, like, if you're not saving the universe, then why even make the game? This being just about you and GlaDOS – and especially given the events of Half-Life, assuming those are going on outside, this is pretty small-scale – it matters to you and her, and probably Wheatley, and nobody else on the planet. They all have bigger things to deal with.

Eurogamer: What kind of function did you want Wheatley to serve as a character and as a voice in the game?

Erik Wolpaw: Well, initially we wanted him to be this little bit of a guide to new players and also a catalyst for events in the sequel.

There's also the idea... Our original character was not Chell from the first game. You were a new test subject, so you don't really know... you have no real relationship with GLaDOS, and you get to a point where you kind of press the button to wake her up, because as a character you didn't really know what your actions were doing.

Erik Wolpaw: Just for the weeks that we were playtesting that, everybody was like, there were these two at-odds ideas: one was "I can't wait till GLaDOS comes back" and the other was "I don't want to wake GLaDOS up." Like, "Why would I want to do that?" I kept thinking: "Because you just told me that you want her to be there!" But players didn't want to do it...

Eurogamer: It's the difference between the player's own motivation and their understanding of the character's motivation.

Erik Wolpaw: Yeah. Yeah. So we get Wheatley in there.

Then at a certain point it was like, are we really going to go through this whole game again with GLaDOS? I don't really know what to do with her arc... We wanted her to go someplace, and we felt that because she's kind of likeable in the first game and people did enjoy being with her, we wanted to have this other, external threat.

I really liked the idea of Wheatley being this guy who's not necessarily inherently bad, but in way over his head. That he's one of those people who is dumb without being necessarily aware of it... And also because it was a puzzle game, and because it was Aperture Science and the idea of science, the idea of the villain being just this thing that's been designed to be an idiot seemed like a nice thing.

And you know, he spends a lot of time obsessing over it. There's little lines in there all the way up that he's kind of... In his mind he's determining who's dumb and who's not, kind of putting himself above you. He immediately goes to assuming you have brain damage and so he's going to take a position of responsibility.

So there's this other thing, which you can barely get away from in games, which is that you need these gates in games – we do it in Half-Life, and every game does it – with the character who's going to wander around with you and open doors for you, basically. And I just really wanted a character who claimed to hack things and then never really managed to ever do it.

And also we wanted someone who sounded different to GLaDOS and who had a warmer, more human-sounding voice. We always had this idea in our heads that you could rate the AIs: the smarter they got, the more computery-sounding they got, and the dumbest AIs would be the ones who sounded perfectly human.

The last thing would be – I think we did an alright job with it, I think we actually pulled it off – I wanted to have this interactive Half-Lifey sort of character that comes with you but then also delivers an actual credible comedic performance from moment to moment. A lot of that was going to be how we set up the scenes and how the animation worked, but a lot of it was going to be having an actor who can deliver an actual comedic performance.

We knew we were going to go with some British comedian. You may or may not know this about Americans, but any time we need to cast someone who sounds authoritative and smart, Americans tend to go to British people, because even the dumbest British guy sounds vaguely smart to us. So we really also liked the idea that the dumbest thing ever manufactured by anyone would have this British accent.

Eurogamer: The humour in the first Portal was extremely dry, and it's a little more obviously sarcastic in Portal 2. I don't want to say "slapstick", but it's broader.

Erik Wolpaw: It is a little bit broader this time. Part of that is what Stephen Merchant brings and... part of it is you get another writer on, so obviously a little bit of his sensibility creeps in. But we wanted to try a couple of things.

The complete sterility and dryness of Portal 1 – we were worried that across 10 hours it would feel very similar to the first one... Our biggest fear going into Portal 2 was that we would just do a retread of Portal 1. Obviously we didn't want to get so far away from it that it was unrecognisable as part of the Portal universe, but... In fact, if we had to choose one of the two, we would rather have done that than simply do something that felt exactly like Portal 1.

And the other thing we wanted to do – Half-Life has this thing where they take these science-fiction scenes that you've seen in movies, and Call of Duty does it as well with war movies – and they kind of rehabilitate them. If you tried to pull it off in a movie, people would be like, "I saw this. I've seen this a million times." But when you're actually doing it interactively it rehabilitates it.

Erik Wolpaw: There's this thing we do a couple of times where they're almost like classic comedy scenes – [Wheatley] falling off the thing, "catch me catch me catch me!" – that you probably couldn't pull off in a movie, but when you're standing there doing it in game it feels a little bit fresh. We could use that same kind of philosophy that games use, but nobody's ever really done it with these classic comedy scenes before. And so we tried them and felt like they were working, and we thought, "Maybe we're getting here before anyone else."

Like, if I was making a modern military shooter nowadays, I'd be terrified, because it seems like every good scene from every good movie has been taken at this point – like, done well, actually recreated.

Eurogamer: There is a lot of comedy in games, but it doesn't seem to be an explicit target for most game-makers to make their games funny.

Erik Wolpaw: I think traditionally comedy games for whatever reason don't do that well... We'll see how Portal does, but if I was about to gamble $20 million of my own money, I'd probably make a game about combat marines in Dubai or something as well.

But having said that, people like comedy, it's just hard to pull off – so if you can pull it off well, people respond to it and they like it, right? There's no shortage of comedy in every other medium – well, ballet maybe doesn't have comedy, I dunno – but the stuff of my diet includes a lot of comedy and it's respected stuff, across a lot of mediums.

So I'd really like to make a really credible comedy game. People seem to be skipping straight to the pure art, and yet nobody's made the Caddyshack in games yet, right? So I'm like, woah woah woah, let's put on the brakes – let's make Caddyshack, and then we can make Anna Karenina or whatever.

There's still this whole untapped area of legitimately you-can-be-proud-of comedy – like, this is not embarrassing, it's not "funny for a game", it's legitimately pretty funny stuff. I'm not saying we necessarily got there, but I'd love to eventually get there.

Video: This is Art. When you hear a buzzer, stare at the Art. (Video: first 15 minutes of Portal 2 co-op.)

Eurogamer: You take the player on quite a journey with GLaDOS in the game, and you end up with a very different relationship with her at the end, she changes quite a lot.

Erik Wolpaw: She resets herself at the end though. She does learn a lesson and then explicitly delete it.

Eurogamer: If you take the first game into consideration as well, where she's just a really cold, alien voice –

Erik Wolpaw: – until the end. At the end she's way more human, and so we wanted to start where she left off. She's upset. She's incredibly upset at you.

You knew, especially if you came back from the previous game – hopefully we set it up a little bit for you – that you had done her wrong, but the hardest part was we needed to get her into another space, because her being angry at you the whole time was going to get old pretty quick.

It was just not going to be particularly pleasant to have her just being cruel to you the whole time, so she changes, and even when she went into the potato there was initially this thing where she was still kind of angry at you, before we found she needed something else to wrestle with, because it was even worse carrying her around and she's just yelling at you from two feet in front of you.

So both Wheatley, and then wrestling with the Caroline thing, gave her this sort of place to go. And we just really liked the idea of her being able to reset herself. This was a fairly early-on idea – we knew we were going to have this arc. It's the idea of having a character arc and then having the character explicitly reject it and just say, "You know what? Done."

The one thing we wrestled with as well was, we wanted the player to feel like they'd beaten her, but we didn't really want you to have to fight her again as a boss battle, so at the end, she does let you go. But it's mainly because there's this tacit admission that you're just too much for her to handle.