Jump to content

Small question about custom functions


Recommended Posts

Also, there is a tiny little typo in the examples, where i -= 0 should be i -= 1.

A little typo that would cause huge problems. Thanks for catching that. You would think after all these years I wouldn't keep making mistakes like that. :)

Link to comment
Share on other sites

Thanks again cdcooley, for your precious advices. Yeah, I use loops in most of these functions, and GetTotalWeight() every time I need to. I use keywords, types, formlists, any way that I can find among available functions to find specific forms while avoiding to miss any custom one if I can.

 

I didn't think of using that new function GetContainerForms() though - I've read all SKSE .psc files and I had completely forgotten about it!.. Truth is unless new functions are documented or somehow listed in the wiki, I find it hard to remember them all... I'm sure you've spared me quite some script latency here! Thanks!

 

Yeah I've already used GetNthForm and GetType in other mods to find ammos or other forms and noticed it was incredibly slow, but since I was using them on the player inventory, I assumed what made it slow was to iterate through all player's stored items - I didn't know that GetType() was also slow, nor that using GetNthForm() on top of it slowed it even more. My understanding from the examples you give here is I could use that kind of loop instead of GetType() in quite a few instances, right?

 

Like, instead of calling "if GetType() == 23", using that loop would be faster?

Function RemovePlayerScrolls(ObjectReference holder)
    Form[] itemList = PlayerRef.GetContainerForms()
    int i = itemList.Length
    while i > 0
        i -= 1
        if itemList[i] as scroll
            PlayerRef.RemoveItem(itemList[i], PlayerRef.GetItemCount(itemList[i]), true, holder)
        endif
    endwhile
EndFunction

Am I understanding you correctly here?

Link to comment
Share on other sites

Hey cdcooley,

 

That's what I figured, thanks a lot for your help, I learnt something here! :). I modified my functions accordingly, adding new variables to be able to use it on several containers at the same time, keywords, formlists, etc. - I also tried to add types as variables without having to call GetType() but couldn't find a way to compile it because I found no way to add types as properties (other than with an Int Property - which would have required to use GetType() in the script anyway).

 

I attached a library script to the MCM config quest - that helped considerably keeping the other scripts significantly shorter :).

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...