ID:141454
 
Code:
        gt
for(var/mob/M in List)
M.battler = src
M.cut = 1
M.overlays += M.weaponicon
icon_state = M.weaponstate
M.icon_state = "Stance"
var/first=M.stats["Spd"]
for(var/mob/O in List)
var/second=O.stats["Spd"]
if(first >= second)
times++
if(times == L.len)
List -=M
src.People.Remove(M)
src.People.Add(M)
times = 0
for(var/mob/M in List)
goto gt//YA DANG RIGHT I USED GOTO


Problem description:
Alright, so I'm trying to arrange the list People by Spd, and I had no clue how to do it, so I slapped this together. And it completely randomly arranges the people...lawlz I can't exactly figure out why...since I don't really have any clue of what kind of operators and equations would work here. Oh btw, I'm moving them from one list to another.
L = list being moved from
People = list being moved to in arranged by speed.
This is the code I use in my game.

mob
proc

Initiatives()
var/list/M=new()
for(var/mob/Monsters/m in view(src))
M.Add(m)
m.factor=(m.agi+(round(rand(m.luck/2))))+rand(1,30)
src.factor=(src.agi+(round(rand(src.luck/2))))+rand(1,30)
for(var/mob/N in src.partylist)
if(N!=src)
N.factor=(N.agi+(round(rand(src.luck/2))))+rand(1,30)
M.Add(N)
M.Add(src)
var/list/N=new()
var/mob/b
for(var/n in M)
b=src.turnpicker(M)
N.Add(b)
M.Remove(b)
return N

turnpicker(var/mob/list/M)
var/mob/N
for(var/mob/m in M)
for(var/mob/n in M)
if(m.factor>n.factor)
if(N)
if(m.factor>N.factor)
N=m
else
N=m
else
if(N)
if(n.factor>N.factor)
N=n
else N=n
return N


Does that all make sense? If not, just ask about it and I will explain whatever you don't get. (BTW factor is a variable all mobs in my game have.)
In response to Satans Spawn
Errmmm...don't I have you on MSN...or had?
In response to Choka
Very potentially... I have lots of people from BYOND on my MSN... I just don't really have the best internet connection to be on MSN lately... I have a low signal strength, and a whopping 24 Mbps. Which is very high compared to my normal 5.5-12Mpbs :D
In response to Satans Spawn
Darn, I was thinking I could've asked you questions there.
In response to Satans Spawn
I get it..sort of...the whole factor bit is a bit...confusing though.

EDIT: No actually I completely understand the turnpicker proc...but the factor thing confuses the flip out of me.
In response to Choka
Well, I could sign in and see how things go if you had some questions right now.
In response to Satans Spawn
Please do!
Theodis's QuickSort library is a good way to quickly sort lists.