One of the first things you will probably want to do is enable script logging. This is off by default in the game, but turning it on is a simple matter of changing just a few ini settings. The three ini settings you will be most interested in for debugging are http://www.creationkit.com/INI_Settings_(Papyrus)#bEnableLogging, which turns on and off the entire script logging system; http://www.creationkit.com/INI_Settings_(Papyrus)#bEnableTrace, which turns on the http://www.creationkit.com/Trace_-_Debug and related functions; and http://www.creationkit.com/INI_Settings_(Papyrus)#bLoadDebugInformation which will load in line number information so you can more easily pinpoint errors.
Once you’ve turned the settings on and launch the game, it should create a Logs folder inside “My Documents/My Games/Skyrim”. Inside that folder should be a “Script” folder. (If you don’t see the Script folder, you may need to launch the game a second time) Your logs will appear inside that folder, named Papyurs.#.log with the number going from 0 to 3. The 0 log is always the newest with older logs cycling through the increasing numbers.
The game should now be outputting some basic information, as well as any errors and trace statements to the 0 log while the game is running, so you should be able to keep an eye on it with your favorite text editor.
If the game detects an error in a script, it will output it in the following format:
stack: - " " Line - " " Line - " " Line ...
Function 0 - the one at the “top” of the stack list - is the function that caused or reported the error. Function 1 is the function that called Function 0. Function 2 called Function 1, and so on. This will help you track down what might be the cause of any issues that are reported.
But maybe you don’t see any errors. What do you do then? Well, you can take advantage of various http://www.creationkit.com/Debug_Script functions, for example http://www.creationkit.com/Trace_-_Debug and http://www.creationkit.com/TraceStack_-_Debug, to help figure out what your script is doing, and what values your various variables or properties have. For an example, take a look at the following function:
Function MyFunction(int coolValue) Debug.Trace("My function called! Coolvalue = "http://forums.bethsoft.com/topic/1345130-having-papyrus-trouble-here-are-some-things-to-try/+ coolValue) If (coolValue == 20) Debug.Trace("Cool value is 20! Doing some neat stuff now!") ; Do neat stuff! EndIfEndFunction
Once you’ve added those trace statements to your function, you can now look at your log to try to pin down what is going wrong. Do you never see “My function called!” in the log? Then whatever is supposed to call your function isn’t happening, so you’ll have to keep looking. Do you see that line but you don’t see “Cool value is 20!”? Then you’ll have to figure out why the value isn’t what you wanted it to be. And you’ll note that in the example, we actually trace out the value of the variable by simply “concatenating” it with the “+” operator.
Skyrim also includes a few console commands that can help you track down what might be the problem. If your script is attached to a quest, type in http://www.creationkit.com/ShowQuestVars into the console to get a list of every Papyrus script attached to the quest, and the contents of all its variables and properties. If your script is attached to a reference, target the reference with your mouse while the console is up (or use the http://www.creationkit.com/PickRefByID command) and then type in http://www.creationkit.com/ShowVars to see the same amount of information, but for the reference. (PgUp and PgDown scroll the console output!) If your script is supposed to be registered for update events, type in http://www.creationkit.com/DumpPapyrusUpdates to have the game dump a list of every single updating form to the Papyrus log so you can see if your script is there. Or, if you think your script might actually be stuck inside an infinite while loop, or taking a while to respond, http://www.creationkit.com/DumpPapyrusStacks will dump everything Papyrus is currently doing to the log for your anolysis.
This only touches the surface of the tools and utilities available for helping to debug your scripts in the game, for more information please check out the http://www.creationkit.com/Category:Papyrus. In particular, the following pages may be quite useful:
- http://www.creationkit.com/INI_Settings_(Papyrus)
- http://www.creationkit.com/Papyrus_Compiler_Errors
- http://www.creationkit.com/Papyrus_Runtime_Errors
- http://www.creationkit.com/Console_Commands_%28Papyrus%29
- http://www.creationkit.com/Debug_Script