AlphaTainer := CreateContainer
#Go through the entire inventory.
#Gets the ID and Quantity of the item in the given slot
WhatItem := ItemInSlot (InventoryLoop)
HowMany := ItemCountInSlot (InventoryLoop)
#If there's no item in the slot, don't bother
if (WhatItem == -1)
then ( )
#But if there is, create a slice to record how many and what type
ItemSlice := CreateContainer
#Now the tricky part.
#We can only do the first three due to the limitations of OHR variables
#This is paranoia: I don't want any old info to carry over from one loop to the next
FirstLetter := 0
SecondLetter := 0
ThirdLetter := 0
#This is also paranoia: I don't want to call a non-extant letter if there's an item smaller than three letters.
If (StringLength (1)>> 0)
FirstLetter := AsciiFromString (1,1)
if (StringLength (1)>> 1)
SecondLetter := AsciiFromString (1,2)
if (StringLength (1)>> 2)
ThirdLetter := AsciiFromString (1,3)
#If you want lower case letters to be treated the same as capitals uncomment the next lines
# FirstLetter := LowerCaseToUpperCase (FirstLetter)
# SecondLetter := LowerCaseToUpperCase (SecondLetter)
# ThirdLetter := LowerCaseToUpperCase (ThirdLetter)
#Now we do some math.
#Each letter is an ascii value from 0 to 255
#By multiplying it, we can combine it into a single value to pass to SetSortOrder. So the final result will be like... 255255255 for LastLetterLastLetterLastLetter
FirstLetter := FirstLetter * 1000000
SecondLetter := SecondLetter * 1000
#If we sorted it now, it'd be backwards, Z to A. So we make the big numbers small and the small numbers big to sort it the right way
# FirstLetter := 0--FirstLetter
# SecondLetter := 0--SecondLetter
# ThirdLetter := 0--ThirdLetter
#Heh! Scratch what I just said. 0-- is the route to Z first, A last. Uncomment the previous 3 lines if you'd rather it be that way.
#Now set the sort order, so they'll be alphabetized later
#And delete the original copy of the item, just like in that movie with that guy
#This quantity thing is probably paranoia
#By this point the script, we've gone through every item in the inventory and the player now has nothing. AlphaTainer is full of references to the treasure they used to have. It's time to restore their former glory.
#But first we gotta alphabetize 'em or everything's pointless
#Gets the handle of the first slice..
AlphaLoop := FirstChild (AlphaTainer)
#So long as there's slices to be tallied, keep tallying..
WhatItem := GetSLiceExtra (AlphaLoop,0)
HowMany := GetSliceExtra (AlphaLoop,1)
#Now adds the proper quantity of items
#Increases AlphaSlot by one and goes to the next slice
AlphaSlot += 1
AlphaLoop := NextSibling (AlphaLoop)
#When there's no more siblings, ALphaLoop will be false, the while loop will break, and everything will be right with the world.
#And now I gotta name and add a billion items to see if this actually works!
#Converts the Ascii for a lower case to its Upper Case form. This way Apple would be sorted to the same place as apple. This is of course, optional.
If (WhatValue >> 96 && WhatValue << 123)
then (ExitReturning (WhatValue -- 32))
else (ExitReturning (WhatValue))
#Frees all the slices to keep them from piling up over the course of the game. I forgot this line at first
#This is just a test to give me items, since I don't actually have a game to test it on