cdcooley Posted June 20, 2016 Share Posted June 20, 2016 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 More sharing options...
Surilindur Posted June 20, 2016 Share Posted June 20, 2016 Haha, no problem. You would be devastated to see my scripts before I have double-checked them. :laugh: Link to comment Share on other sites More sharing options...
Hoamaii Posted June 20, 2016 Author Share Posted June 20, 2016 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 More sharing options...
cdcooley Posted June 21, 2016 Share Posted June 21, 2016 Yes. As long as there's a matching script type for what you need you can use it that way and it will be much faster. Link to comment Share on other sites More sharing options...
Hoamaii Posted June 22, 2016 Author Share Posted June 22, 2016 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 More sharing options...
Recommended Posts