Subtitles (Portal 2)

From Valve Developer Community
Revision as of 06:18, 22 July 2011 by Chickenmobile (talk | contribs) (Created page with "Closed Captions (or subtitles) are mainly used for displaying Actor's dialogue for players that are hearing-impaired or have no sound. Simple world sounds may be listed in th...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Closed Captions (or subtitles) are mainly used for displaying Actor's dialogue for players that are hearing-impaired or have no sound. Simple world sounds may be listed in the captions to simulate different noises or effects, such as doors closing or explosions. Subtitles are deemed to be important when it comes to medium to large sized mods as the mod would be distributed to a much wider audience than what a single map would.

Captions can also be used to indicate where dialogue will be, but has not been recorded yet, as recording masses amounts of sounds can be time consuming when in production of the level.


In Portal 2 the captions automatically appear when an actor speaks (if defined) inside the specific scene file, however, creating custom scene files are impossible without having to completely re-compile the scenes.image file. Therefore a workaround is needed.


Note.png Note: This tutorial will assume that you already have your (custom) sound implemented in your map and will use the name of the examples for consistency.

Creating the caption file

Firstly, create the captions inside a text file located in the Steam/steamapps/common/Portal 2/portal2/resource folder. The format of the captions should look like this:


lang
{ 
	Language "English"
	Tokens 
	{ 
		character.example1	"This is an example caption."
		character.example2	"You should be able to see captions on the screen."
	}
}


  • Save the .txt file in the UCS-2 Little Endian or UTF-16 LE format. Use Notepad++ or another advanced text editor to do this.
  • The captions should be in quotation marks to indicate the caption text.
  • The name of the caption should be the name of a soundscript not the name of the sound.
  • Save the .txt file with the prefix closedcaption_ as this will be necessary to play the captions.

Compiling the .txt file into a .dat file

In order for the captions to be able to be seen in game, the captions must be compiled into a .dat file. This can be done using the captioncompiler executable located inside the Portal 2/bin file.

Go to Start -> Run and type in cmd to bring up the command prompt. Navigate to the captioncompiler.exe file and drag it into the command prompt. Then use the input -v "closedcaption_NameOfFile.txt" after it. Like so:


"U:/Program Files/Steam/steamapps/common/Portal 2/bin/captioncompiler.exe" -v "closedcaption_NameOfFile.txt"


This will compile the captions into the file which can run in game. Keep the compiled file inside the resource folder.


Note.png Note: If the file refuses to compile because the Game Directory is different from the portal 2 folder, change it by making a duplicate entry in the gameinfo.txt with the paths leading to the Portal 2/portal2 directory. Then run SourceSDK with the custom parameters to make Portal 2 the active mod.

Making the captions appear in game

Since making scenes are out of the option for making the captions appear, it is necessary to manually make the captions appear using entities inside the hammer editor or using a script.

  1. Create or use a point_servercommand.
  2. Create a logic_auto and put the output with the name of the caption file:
My Output Target Target Input Parameter
OnMapSpawn @servercommand Command cc_lang NameOfFile

     3. Using whichever method to activate the sound or caption add these outputs:

My Output Target Target Input Parameter
OnAnOutput @servercommand Command cc_emit character.example1
  • Make sure to also activate the preferred sound at the same time. (This was the whole reason for the captions).


Note.png Note: Only put the name of the caption file after closedcaption_ when using the cc_lang input as it will not play the captions otherwise.

Caption Codes (Portal 2)

<sfx>
Marks a line as a sound effect that will only be displayed with full closed captioning. If the user has cc_subtitles set to "1", it will not display these lines.
<clr:255,255,255>
Sets the color of the caption using RGB color; 0 is no color, 255 is full color. For example, ;<clr:255,0,0> would be red.
<b>
Bolds all text following the tag.
<i>
Italics text following the tag.
<len:#>
Indicates how long the caption should appear on the screen.
<norepeat:#>
Sets how long until the caption can appear again. Useful for frequent sounds.

An example of how to use a code tag:

lang
{ 
	Language "English"
	Tokens 
	{ 
		character.example1	"<clr:255,0,0><b> Character: This is an example caption."
		character.example2	"<clr:255,0,0><len:3> Character: You should be able to see captions on the screen."
	}
}

See also