Jump to content

Scripting, AddForm/HasForm


highstresslevel

Recommended Posts

EDIT: Nevermind, figured it out.

 

-----

 

What I'm trying to do:

 

Basic chest you dump random items in. When you close it, the script runs and sorts everything into other chests.

 

Code that isn't working:

 

EVENT OnActivate(ObjectReference akActionRef)

wait(3)

xcsRunSort()

endevent

 

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

xcsItemsToSort01.AddForm(akBaseItem)

endEvent

 

Function xcsRunSort()

xcsSortingPhaseOneStarted.Show()

Int iIndex = xcsItemsToSort01.GetSize()

While iIndex > 0

iIndex -= 1

xcsBaseItem = xcsItemsToSort01.GetAt(iIndex) As ObjectReference

Int xcsItemCount = self.GetItemCount(xcsBaseItem)

xcsSortItems(xcsBaseItem, xcsItemCount)

EndWhile

xcsItemsToSort01.Revert()

xcsSortingPhaseOneComplete.Show()

endFunction

 

If I bypass this part, and just dump everything right into the sorter with xcsSortItems(akBaseItem, aiItemCount) from OnItemAdded, then it works. Potions get sent to the potions rack, books to the book shelves, swords to the sword rack, ect.

 

But its laggy, especially if you add things to the chest too quickly. Items can get sent to the wrong shelf or vanish completely. For this to actually work, I need the formlists.

 

When I run the code with this part enabled:

 

I put the items in the chest, close it, "Sorting has started" message displays. There's a delay, longer the more items I added. "Sorting complete" message. But the items are still in the chest and the destination chests are empty. If I open the chest and close it again, both messages are displayed with no delay between.

 

So it seems to be building the formlist, using it to set the loop, and then clearing it like it should. Its just not getting the objectReference and sending it off. Why?

 

-----

 

Nevermind, solved. Should have been xcsBaseItem = xcsItemsToSort01.GetAt(iIndex) As Form.

 

I feel like an idiot.

Edited by highstresslevel
Link to comment
Share on other sites

  • Recently Browsing   0 members

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