Harvey2112 Posted June 5, 2012 Share Posted June 5, 2012 The following code snippet is designed to store a single copy of each Book acquired into the reference container (xGSxBookStoreREF). The script currently walks through a formlist of all books (xGSxBooksFLST) and then runs conditional tests on the player's inventory and the reference container, moving a single copy if a new title. The script works fine but takes forever and a day. I am open to new ideas on how to accomplish my goal more quickly. If iButton == 0 ; Store New Books Notification("Painfully slow book sort. Please go about your business until the menu returns") Int iIndex = xGSxBooksFLST.Getsize() while (iIndex > 0) iIndex -= 1 Book CurrentBook = xGSxBooksFLST.GetAt (iIndex) as Book IF Game.GetPlayer().GetItemCount(CurrentBook) > 0 IF xGSxBookStoreREF.GetItemCount(CurrentBook) >= 1 Else Game.GetPlayer().RemoveItem(CurrentBook, 1, True, xGSxBookStoreREF) EndIF EndIF Endwhile Notification("New Books stashed") iButton = xGSxBooksMenu.Show() Endif Link to comment Share on other sites More sharing options...
fg109 Posted June 5, 2012 Share Posted June 5, 2012 The way you're doing it is a good way to do it... not sure if it's possible to speed it up. I can only think of one other way to do it. If you look at the notes for RemoveItem, you will see that it allows you to pass in a formlist as the parameter. So you could try changing your code to this: Scriptname fg109TestMEScript extends ActiveMagicEffect FormList Property xGSxBooksFLST Auto ObjectReference Property xGSxBookStoreREF Auto Message Property xGSxBooksMenu Auto Event OnEffectStart(Actor akTarget, Actor akCaster) int iButton = xGSxBooksMenu.Show() if (iButton == 0) ; Store New Books Debug.Notification("Begin Book Sort") xGSxBookStoreREF.RemoveAllItems(Game.GetPlayer()) ;move all items into player inventory Utility.Wait(0.5) ;probably not neccessary, but better safe than sorry Game.GetPlayer().RemoveItem(xGSxBooksFLST, 1, True, xGSxBookStoreREF) ;move 1 of every item in the list from player to container Debug.Notification("End Book Sort") endif EndEvent It compiles successfully, but I have no idea how well it works. Link to comment Share on other sites More sharing options...
Harvey2112 Posted June 5, 2012 Author Share Posted June 5, 2012 Much, much faster. Eliminating the need to walk through the formlist was a breakthrough. I knew a fresh set of eyes would help. :thumbsup: Link to comment Share on other sites More sharing options...
Recommended Posts