Subtitles (Portal 2): Difference between revisions
(Added hint that a soundscript isn't needed. Added workaround in case captioncompiler can't find the game. Added info on how to use both custom and official subtitles in a map.) |
Le Glaconus (talk | contribs) (a person was confused by that) |
||
(19 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
{{LanguageBar}} | |||
[[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. | [[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. | ||
Line 4: | Line 6: | ||
In Portal 2 the captions automatically appear when an actor speaks (if defined) inside the specific [[Logic choreographed scene|scene]] file | In Portal 2 the captions automatically appear when an actor speaks (if defined) inside the specific [[Logic choreographed scene|scene]] file. however, creating custom scene files are impossible without having to completely re-compile the scenes.image file. Therefore a workaround described below is needed. | ||
{{ | {{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 == | == Creating the caption file == | ||
Firstly, create the captions inside a text file located in the | Firstly, create the captions inside a text file located in the {{path|Steam/steamapps/common/Portal 2/portal2/resource}} folder. The format of the captions should look like this: | ||
Line 32: | Line 34: | ||
== Compiling the .txt file into a .dat file == | == Compiling the .txt file into a .dat file == | ||
The captions must be compiled with <code>captioncompiler.exe</code>. Make sure the SDK Launcher is set to the game folder, then simply drag your caption file onto it. The caption file must be dragged from the mod resource directory in order to produce the .dat file. e.g. {{path|C:\Program Files (x86)\Steam\steamapps\common\Portal 2\portal2_dlc3\resource\}}. | |||
This process will become slightly easier if you create a batch command file in the resource folder. Copy the following code into a text file and save it as a .bat file in your resources folder: | |||
<syntaxhighlight lang=winbatch> | |||
"[path to Portal 2 folder starting from C:]\bin\captioncompiler.exe" %1 | |||
pause | |||
</syntaxhighlight> | |||
In some cases, it may be beneficial to change <code>%1</code> to <code>%~nx1</code>. | |||
{{tip|With a batch file, you can use the <code>-game "path to gameinfo.txt"</code> parameter to override the global [[Game Directory|vproject]] value. Place it after <code>%1</code>, leaving a space. This saves you from having to launch the SDK and change it there.}} | |||
Drag your caption .txt files onto the Batch file to use it as you would the .exe itself. | |||
== Making the captions appear in game == | == 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 [[logic_script|script]]. | Since making scenes are out of the option for making the captions appear (only for workshop maps, mod-makers can indeed make their own [[scenes.image]]), it is necessary to manually make the captions appear using entities inside the hammer editor or using a [[logic_script|script]]. | ||
# Create or use a [[point_servercommand]]. | # Create or use a [[point_servercommand]]. | ||
# Create a [[logic_auto]] and put the output with the name of the caption file '''without the prefix closecaption_''': | # Create a [[logic_auto]] and put the output with the name of the caption file '''without the prefix closecaption_''': | ||
{| | {| border=1 cellpadding="2" cellspacing="1" | ||
!My Output | |- align=left style="background:#DCDCDC; color:black" | ||
!Target | ! | ||
!Target Input | ! My Output > !! Target Entity !! Target Input !! Parameter !! Delay !! Only Once | ||
!Parameter | |||
|- | |- | ||
| OnMapSpawn | | [[File:Io11.png]] || OnMapSpawn || @servercommand || Command || cc_lang NameOfFile || 0 || No | ||
| @servercommand | |||
| Command | |||
| cc_lang NameOfFile | |||
|} | |} | ||
3. Using whichever method to activate the sound or caption add these outputs: | 3. Using whichever method to activate the sound or caption add these outputs: | ||
{| | {| border=1 cellpadding="2" cellspacing="1" | ||
!My Output | |- align=left style="background:#DCDCDC; color:black" | ||
!Target | ! | ||
!Target Input | ! My Output > !! Target Entity !! Target Input !! Parameter !! Delay !! Only Once | ||
!Parameter | |||
|- | |- | ||
| OnAnOutput | | [[File:Io11.png]] || OnAnOutput || @servercommand || Command || cc_emit character.example1 || 0 || No | ||
| @servercommand | |||
| Command | |||
| cc_emit character.example1 | |||
|} | |} | ||
{{note|Replace {{code|OnAnOutput}} with a real output.}} | |||
* Make sure to also activate the preferred sound at the same time. (This was the whole reason for the captions). | * Make sure to also activate the preferred sound at the same time. (This was the whole reason for the captions). | ||
{{ | {{note|Do not use the prefix <code>closecaption_</code> when calling the file like this. When using the command {{cmd|cc_lang}}, the game automatically adds that prefix, so you would end up calling <code>closecaption_closecaption_NameOfFile</code>. Please visit the [[Talk:Subtitles (Portal 2) |discussion section]] of this page for an example.}} | ||
If you use original scene files in your map but only have a few custom voice lines, you shouldn't change the cc_lang OnMapSpawn, as people will not see the subtitles for the original scenes this way. Instead, activate your custom subtitles file only when needed. Like so: | If you use original scene files in your map but only have a few custom voice lines, you shouldn't change the cc_lang OnMapSpawn, as people will not see the subtitles for the original scenes this way. Instead, activate your custom subtitles file only when needed. Like so: | ||
{| | {| border=1 cellpadding="2" cellspacing="1" | ||
!My Output | |- align=left style="background:#DCDCDC; color:black" | ||
!Target | ! | ||
!Target Input | ! My Output > !! Target Entity !! Target Input !! Parameter !! Delay !! Only Once | ||
!Parameter | |||
!Delay | |||
|- | |- | ||
| OnAnOutput | | [[File:Io11.png]] || OnAnOutput || @servercommand || Command || cc_lang NameOfFile || 0 || No | ||
| @servercommand | |||
| Command | |||
| cc_lang NameOfFile | |||
| 0 | |||
|- | |- | ||
| OnAnOutput | | [[File:Io11.png]] || OnAnOutput || @servercommand || Command || cc_emit character.example1 || 0.1 || No | ||
| @servercommand | |||
| Command | |||
| cc_emit character.example1 | |||
| 0. | |||
|- | |- | ||
| OnAnOutput | | [[File:Io11.png]] || OnAnOutput || @servercommand || Command || cc_lang || 0.2 || No | ||
| @servercommand | |} | ||
| Command | |||
| cc_lang | |||
| 0. | |||
|} | |||
Using the command cc_lang without defining which one in the final Output will make the game use the language of the Game_UI again, while still playing the custom subtitles activated 0.1 seconds earlier. | Using the command cc_lang without defining which one in the final Output will make the game use the language of the Game_UI again, while still playing the custom subtitles activated 0.1 seconds earlier. |
Latest revision as of 10:42, 15 June 2025
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 described below is needed.

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. However, this will work without creating a soundscript.
- Save the .txt file with the prefix closecaption_ as this will be necessary to play the captions.
Compiling the .txt file into a .dat file
The captions must be compiled with captioncompiler.exe
. Make sure the SDK Launcher is set to the game folder, then simply drag your caption file onto it. The caption file must be dragged from the mod resource directory in order to produce the .dat file. e.g. C:\Program Files (x86)\Steam\steamapps\common\Portal 2\portal2_dlc3\resource\
.
This process will become slightly easier if you create a batch command file in the resource folder. Copy the following code into a text file and save it as a .bat file in your resources folder:
"[path to Portal 2 folder starting from C:]\bin\captioncompiler.exe" %1
pause
In some cases, it may be beneficial to change %1
to %~nx1
.

-game "path to gameinfo.txt"
parameter to override the global vproject value. Place it after %1
, leaving a space. This saves you from having to launch the SDK and change it there.Drag your caption .txt files onto the Batch file to use it as you would the .exe itself.
Making the captions appear in game
Since making scenes are out of the option for making the captions appear (only for workshop maps, mod-makers can indeed make their own scenes.image), it is necessary to manually make the captions appear using entities inside the hammer editor or using a script.
- Create or use a point_servercommand.
- Create a logic_auto and put the output with the name of the caption file without the prefix closecaption_:
My Output > | Target Entity | Target Input | Parameter | Delay | Only Once | |
---|---|---|---|---|---|---|
![]() |
OnMapSpawn | @servercommand | Command | cc_lang NameOfFile | 0 | No |
3. Using whichever method to activate the sound or caption add these outputs:
My Output > | Target Entity | Target Input | Parameter | Delay | Only Once | |
---|---|---|---|---|---|---|
![]() |
OnAnOutput | @servercommand | Command | cc_emit character.example1 | 0 | No |

- Make sure to also activate the preferred sound at the same time. (This was the whole reason for the captions).

closecaption_
when calling the file like this. When using the command cc_lang, the game automatically adds that prefix, so you would end up calling closecaption_closecaption_NameOfFile
. Please visit the discussion section of this page for an example.
If you use original scene files in your map but only have a few custom voice lines, you shouldn't change the cc_lang OnMapSpawn, as people will not see the subtitles for the original scenes this way. Instead, activate your custom subtitles file only when needed. Like so:
Using the command cc_lang without defining which one in the final Output will make the game use the language of the Game_UI again, while still playing the custom subtitles activated 0.1 seconds earlier.
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."
}
}