Skip to content
Alex Dunn edited this page Aug 21, 2014 · 7 revisions

Unlike Papyrus, writing an SKSE plugin allows you to do anything you want. Your power is unlimited, which means it's also extremely easy to break things in Skyrim and to make the game crash. In Papyrus, when you pass something to a function that doesn't make sense, Papyrus is smart enough to just silently stop executing the script in question. On the other hand, SKSE plugins operate at a much lower level and do not have any of this safety. You can easily make the game unstable, destroy user data in the game, and make the game crash if you aren't very careful with your code.

  • Always check that the parameters passed into the function are not null:
void myFunction(StaticFunctionTag* base, TESObjectREFR* pContainerRef) {
    if (!pContainerRef) {
        return;           // This will silently stop executing the function before it tries to do something to nothing
    }
    // Implement the rest of your code here...
}
  • In the same way, always check that a function with a return value has returned something other than null:
void myGetForm(StaticBaseForm* base, TESObjectREFR* pContainerRef) {
    TESForm* pBaseForm = pContainerRef->baseForm;
    if (pBaseForm) {
        // Implement the rest of your code here...
    }
}
  • In cases where the item returned by a function also has a property such as a count of how many there are, you might also want to check that it isn't 0, depending on what you're doing:
ExtraContainerChanges::EntryData* extraData = (*iteratorPosition);
if (extraData && (extraData->countDelta > 0)) {
    // Implement the rest of your code here...
}

This code can actually be seen in action in PapyrusObjectReference.cpp

  • For a truly robust SKSE plugin, you should execute these tests after EVERY variable assignment you make in your code.