Sort_grid()
set
hidden = 1
var/namesort = winget(src, "map.sort1","is-checked=true")
var/list/sortlist = list()
var/list/itemlist = list()
var/position = 1
var/position2 = 1
var/sortpos = 1
var/maxpos = 0
var/obj1
var/obj2
if(namesort == "true")
if(src.viewer == "Inventory")
for(var/obj/item/I in usr.contents)
sortlist += I.name
itemlist += I.name
maxpos = sortlist.len
var/list/sorted[sortlist.len]
startnamesort //for goto
for(position2 = 1; position2 < maxpos; position2 ++)
if(!sorted.Find(itemlist[position2]))
obj1 = itemlist[position2]
else
continue
for(position = 1; position < sortlist.len; position++)
obj2 = sortlist[position]
switch(sorttext("[obj1]","[obj2]"))
if(1)
sorted[sortpos] = obj1
if(-1)
sorted[sortpos] = obj2
obj1 = sorted[sortpos]
sortlist -= sorted[sortpos]
sortpos++
if(sorted[maxpos] == null)
world << "goto"
position2 = 1
sortpos -= 1
goto startnamesort
Problem description:
It's very likely that I'm making this way more complicated than it seems, but here goes. Basically, I'm implementing some sorting functions to the grids for my game that will let you sort the contents based on different parameters (IE name, item type, element, etc).
I've spent a couple hours sorting this out, and I've got it to the point where it'll sort everything in order EXCEPT for the last object in the list, whatever happens to be last in the alphabetical order list. The reason is because the sortpos var is set at one.
Simply solution right? Set it to 0. Nope, it make dream seeker crash doing that. I have no idea why. Any ideas?
Thanks guys.
Alternatively I could offer to use Bubble Sort: