ID:163686
 
Im trying to find a way to check for the largest var within a list.

lets say i have a list called sizelist and within the list is a bunch of objs, and each obj has a var called "size" i need a way to find out WICH obj has the largest "size" var within the "sizelist" list... so far i got this much



for(var/obj/I in sizelist)


Yeah thats it haha. so any help?
Look up sorting procedures in the libraries or on the forum. They basically take a list of, let's say, numbers and arranges them into ascending or descending from which it's easy to pick out the biggest one.
What you can do is essentially define a variable as the carrier of the current largest object. When you loop through all of the objects, compare the current object with the carrier. If the carrier is empty, or if the current object's size is larger than the carrier's size, then set the object to the carrier. When the for loop has finished, the variable you defined will either be the largest item in a list, or null when the list is empty.

var/obj/largest
for(var/obj/I in container)
if(!largest|| I.variable > largest.variable)
largest= I
if(largest)
...