Sublime Text

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search

Sublime Text is an extensible text-editor with a robust package system based on Python that makes it very flexible. Sublime Text is not free software, but offers an unlimited and unrestricted evaluation version. It can be purchased or evaluated on the official website.

See Wikipedia's page for more information.

Installation[edit | edit source]

Install Sublime[edit | edit source]

  1. Go to the Sublime Text website and install the latest release of version 2 or 3.
  2. Run the program at least once so it will set up its preferences.

Install Plugin[edit | edit source]

  1. Download File:PapyrusF4.zip
  2. Extract the zip file to %APPDATA%\Sublime Text 2\Packages directly - or extract it somewhere else and drag in the PapyrusF4 folder to the packages folder.
    • If you installed Sublime Text 3, the location is %APPDATA%\Sublime Text 3\Packages instead

If no previous Papyrus plugin[edit | edit source]

  1. In Sublime, press CTRL + SHIFT + P to type the command: "PapyrusF4" -> PapyrusF4 INI: Create default INI file. This will create the file %USERPROFILE%\Documents\SublimePapyrusF4.ini and open it in the editor.
  2. Make the following changes:
    • Point "scripts=" at your script source folder
    • Point "compiler=" and "assembler=" at the compiler and assembler exe files in your PC folder
    • Point "output=" at your "Data\Scripts" folder
    • Change "wiki=" to "wiki=http://www.creationkit.com/fallout4/"

If you have the old Papyrus plugin[edit | edit source]

Follow the above steps for if you have no Papyrus plugin, then do the following:

  1. In Sublime, open an existing PSC file
  2. Select View -> Syntax -> Open all with current extension as... -> PapyrusF4 -> PapyrusF4

Additional Steps[edit | edit source]

Due to the addition of several new auto-complete options for functions, you may find Sublime accepting "Enter" to auto-complete to be annoying. (As an example, try typing endif and hitting ↵ Enter to add a new line) To disable this and only allow Tab ↹ to auto-complete, do the following:

  1. Select Preferences -> Settings - User
  2. Add the following to the file, between the { and } characters. If there is already other settings in there, make sure they are all separated by commas.
"auto_complete_commit_on_tab": true

Build Types[edit | edit source]

The Sublime Papyrus plugin supports three different build types - debug, release, and release final. These are identical to the build types exposed in the Creation Kit. The normal build option, invoked with Ctrl+B, is a "debug" build. It will produce non-optimized code, with all debug commands intact.

To access the other build types, open the Sublime command palette (Ctrl+⇧ Shift+P) and type in "Build". Then select either release (optimized + debug stripping) or release final (optimized + debug and beta stripping).

You will generally want to do debug builds for testing and development, with final builds for release.

Existing Snippets[edit | edit source]

The Sublime plugin comes with a selection of existing snippets you can use. These are accessed by typing a function name or event in lowercase (part of the name works too) and selecting the snippet from the popup menu in Sublime with the Enter or Tab keys (depending on your settings).

There are also additional snippets that aren't a specific function or event, listed below:

  • astate (Auto state): Creates an auto state block with the cursor at the state name.
  • event: Creates an event definition with the cursor at the event name, and can be tabbed to the parameters. Usually you will want to use one of the predefined event completions instead so you don't have to remember the parameters.
  • for: Creates a pseudo-for loop using the while command with a counter and a maximum count. Use Tab to navigate between counter name and max count.
  • forEach: Creates a pseudo-for-each loop using the while command. Basically identical to the for snippet, but uses the array's length as the max count. Tab navigates between counter and array names.
  • fun: Creates a function definition with the cursor at the function name, and can be tabbed to the parameters.
  • group: Creates a property group definition with the cursor at the group name.
  • if: Creates an if/endif block with the cursor at the condition line.
  • property: Creates an auto property definition with the cursor starting at the property type. Tab will cycle through to the name, const, and mandatory flags.
  • propertyFull: Creates a full property definition with a backing variable and simple get/set functions. Tab will cycle through type, name, and mandatory flag.
  • state: Creates a state block with the cursor at the state name.
  • struct: Creates a struct block with the cursor at the struct name.
  • while: Creates a while block with the cursor at the condition.

Adding Snippets[edit | edit source]

The existing Papyrus package for Sublime Text includes a number of snippets that will auto-complete to frequently used things (like typing "onhit" and then tab will create a proper OnHit event so you don't have to constantly be looking up the syntax). If you want to make more of these, you can simply add another .sublime-snippet file to the Package directory. Documentation on snippets is available at Sublime Text docs site.

Tips 'n' Tricks[edit | edit source]

  • Drag your scripts directory to the Sublime Text window to have it opened as your current project. Now hit Ctrl+P. You have access to all your scripts here, with it narrowing down the list as you type. It's even smart enough to translate "comph" into "CompanionsHousekeepingScript," so whatever kinds of nutty shorthand you can think of for your scripts will probably work.
  • In a long file with lots of functions, hit Ctrl+R. You're now looking at a list of functions that you can navigate the same way.
  • Combine the two of them. Ctrl+P, type to find your file. Add an "@" at the end of it when you have the one you want, and you can go directly to the function in question. So comph@reoprq takes me right to the "ReOpenAllRadiantQuests" in CompanionsHousekeepingScript.psc. And since it works as you type, you don't even have to remember that much.
  • After you hit Ctrl+B to compile, if there are any errors, you can hit F4 to cycle through them.
  • Holding Ctrl+⇧ Shift lets you move lines up and down with the arrow keys.
  • Ctrl+⇧ Shift+D duplicates a line.
  • Highlight a word, then press Ctrl+D to highlight every other instance of that word in succession -- makes renaming variables simple!
  • Drag with the middle mouse button for a vertical select.
  • If you've set up Perforce, you can use the Perforce commands in the FalloutF4 right-click menu (they are also in the command palette). This lets you view old versions of the file you're looking at, perform diffs from the current version against those old versions, and compare what is currently on your disk to what is in the repository.
  • All Events that the compiler supports have been added as snippets, so if you type the name of the event and hit Tab ↹, it will autocomplete to the full event (with parameters) so you don't have to check the wiki for syntax. Snippets are case-sensitive, and all event names are set as lower-case, so you'll need to type the name in lower-case to see it.
    • For remote-registered events, use the name of the event followed by "-REM" to have the correct syntax filled out
    • For reference collection aliases, use the name of the event followed by "-RC" to have the sender parameter auto-added
    • Both of the above are combined into "-REM-RC" if you happen to need a remote event from a ref collection alias.
  • All the functions on the wiki have been added as snippets. You can type part of the function name (in lower-case) and hit Tab ↹ to fill out the function with all the parameters. Hit Tab ↹ to switch between each parameter.
  • Place your cursor inside a function name and hit F1 to open the wiki documentation on that function. If there's more than one function with the name, it'll give you a choice as to which one you want to see.
    • You can also do this by right-clicking and selecting PapyrusF4 -> Wiki Documentation.
    • Because Sublime lets you do multiple selections, if you have more than one cursor sitting in a function name, it will attempt to look up documentation for all of them and open them in tabs.

Advanced Users[edit | edit source]

Multiple "Projects"[edit | edit source]

The ini file supports specifying multiple "projects" by simply adding another section with a name of your choice and setting up the ini settings with the correct values. For script files, the plugin will see which source folder the script is in to pick a project. For assembler and compiled files it will instead check the output folder.

Example:

[Fallout4]
scripts=E:\Games\Fallout4\Build\Source\Scripts
compiler=E:\Games\Fallout4\Build\PC\Papyrus Compiler\PapyrusCompiler.exe
assembler=E:\Games\Fallout4\Build\PC\Papyrus Compiler\PapyrusAssembler.exe
output=E:\Games\Fallout4\Build\PC\Data\Scripts
<additional Fallout4 settings here...>

[Fallout4-DLC]
scripts=E:\Games\Fallout4-DLC\Build\Source\Scripts
compiler=E:\Games\Fallout4-DLC\Build\PC\Papyrus Compiler\PapyrusCompiler.exe
assembler=E:\Games\Fallout4-DLC\Build\PC\Papyrus Compiler\PapyrusAssembler.exe
output=E:\Games\Fallout4-DLC\Build\PC\Data\Scripts
<additional Fallout4-DLC settings here...>

Assembling and Disassembling Papyrus PEX files[edit | edit source]

If you open a PEX file in Sublime it will show up as a binary file. If you set the "syntax" (via the View menu) to "Compiled PapyrusF4" and hit "Build", Sublime will disassemble the PEX file for you into a PAS file which will then be auto-opened in Sublime with proper syntax coloring.

Note that the PEX file needs to be in an "output" folder specified in the ini file for this to work.

You can then tweak the PAS file and re-assemble it into a PEX by building the PAS file.

Note that the normal script compiler will delete the PAS file if it is found, so if you want to keep it, make a copy.

See Also[edit | edit source]