Jump to content
  • entries
    17
  • comments
    41
  • views
    12,062

Stop sucking at GetFormFromFile()


darkconsole

1,456 views

Today's rant brought to you by mods like Auto Unequip Ammo and 80% of the other mods out there.

 

Dynamic support is great. Do you have devious devices? No? Ok, I'll disable devious device features. This is brilliant.

 

What is not brilliant is this:

[04/06/2015 - 12:53:43PM] ========== Auto Unequip Ammo: Scanning for supported plugins...

[04/06/2015 - 12:53:43PM] ========== ERRORS RELATED TO MISSING FILES SHOULD BE IGNORED!

[04/06/2015 - 12:53:43PM] ERROR: File "XFLMain.esm" does not exist or is not currently loaded.

stack:

<unknown self>.Game.GetFormFromFile() - "<native>" Line ?

[AUA (1C00C6C2)].AUAQuestScript.GameLoaded() - "AUAQuestScript.psc" Line 40

[AUA (1C00C6C2)].AUAQuestScript.OnUpdate() - "AUAQuestScript.psc" Line 73

 

How about instead of printing an error about ignoring errors, about how you just not fucking throw any errors to start with? If you honestly don't know how, then, please take note. Make the function Game.GetModByName() your best goddamn friend in the universe.

 

If you are a programmer outside of Skyrim, especially if you are like a programmer for money... I sure hope you aren't being as bad in that code either. If so you should feel terrible about charging money for failing code. If you are new to coding and Skyrim, then take heed now to prevent starting any retarded habits.

If(Game.GetModByName("MyOptionalMod.esp") != 255)    MyForm = Game.GetFormFromFile(0x1234,"MyOptionalMod.esp")EndIf

Wrapping your GetFormFromFile() with a test that your file actually exists (GetModByName()) means that when it does not exist you can do two things: avoid having the game throw excess errors in the log, and then handle the failure gracefully.

 

From the CK Wiki:

Calling this function on a non-existent plugin will not result in any log output, and so it may be used strategically before calling something like GetFormFromFile() to avoid creating log errors. (Or in place of GetFormFromFile entirely, if you only want to check if the plugin is present).

3 Comments


Recommended Comments

Guest Retired

Posted

Way to go.

 

MoreNastyCritters, are you reading this?

Link to comment

Hi,
 

Using the method you suggest requires SKSE, which not all authors are comfortable with requiring. This error alone is not reason enough to require SKSE.

 

However,  in Campfire and future versions of Frostfall, et al, I use the following function to check for plugins. It changes its behavior depending on if SKSE happens to be loaded or not, and if it is, it surpresses errors. It's still up to the user to use SKSE or not in this case.
 

bool property isSKSELoaded auto hidden

; In some other function or event, extend if specific version is necessary
isSKSELoaded = SKSE.GetVersion()
 
bool function IsPluginLoaded(int iFormID, string sPluginName)
    if isSKSELoaded
        int i = Game.GetModByName(sPluginName)
        if i != 255
            debug.trace("[ModName] Loaded: " + sPluginName)
            return true
        else
            return false
        endif
    else
        bool b = Game.GetFormFromFile(iFormID, sPluginName)
        if b
            debug.trace("[ModName] Loaded: " + sPluginName)
            return true
        else
            return false
        endif
    endif
endFunction

I hope that snippet can help others implement this kind of functionality even if they don't require SKSE from their users.

 

Edit: Removed everything related to issues I have with the tone of this article and just provided information instead.

Link to comment

i disagree. it is. disk operations are slow.

 

that is a lot of papyrus vm side convolution to avoid requiring the one thing that is almost kind of basically required by everything else, even if they dont know it, to do a simple check. the fact someone could be opposed to skse actually quite boggles me, unless you got bad blood with the people or something. i know i dont need to lecture you about how many ms per frame we have to run, or how easy it is to stall out threads in the vm.

 

hell, i wouldn't even have access to bitwise operations without skse.

Link to comment
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use