ID:2423533
 
Code:


Problem description:
Hey, was wondering if there was a code that would help find the greatest value out of a bundle of mobs, objs, etc.

Like if I was looking for someone who had the most kills in an arena. How would I go about it?
Bunch of ways to do it:
var whatever/highest_thing
for(var/whatever/thing in things)
if(!highest_thing || thing.value > highest_thing.value)
highest_thing = thing
return highest_thing

Slightly more efficient because it doesn't read value more than once per thing:
var
whatever/highest_thing
highest_value = -1#INF

whatever/thing
value

for(thing in things)
value = thing.value

if(value > highest_value)
highest_thing = thing
highest_value = value

return highest_thing

Or you could sort things in the list by value. There are libraries for list sorting.
In response to Kaiochao
Thanks! This really helped a lot. Appreciate it.