scoreboard
addScore(mob/m)
..()
if(m.key in src.scores)
if(m.number.value > src.scores[m.key]["value"])
src.scores[m.key] = list("value"=m.number.value,\
"mob_name"=m.name,\
"date"=world.timeofday)
else
src.scores.Add(m.key)
src.scores[m.key] = list("value"=m.number.value,\
"mob_name"=m.name,\
"date"=world.timeofday)
if(src.scores.len > 5)
src.scores.Cut(src.MAX, src.scores.len)
sortScores()
//bubblesort
if(src.scores.len > 1)
for(var/i=1, i<src.scores.len, i++)
var/list/L1 = src.scores[i]
var/n1 = L1["value"]
world<<n1
var/list/L2 = src.scores[i+1]
var/n2 = L2["value"]
world<<n2
if(n1 < n2)
src.scores.Swap(i, i+1)
Problem description:
The line that poops out the bad index is the line where I define n1.
runtime error: bad index
proc name: sortScores (/scoreboard/proc/sortScores)
source file: Scoreboard System.dm,67
usr: Spunky_Girl (/mob)
src: /scoreboard/str (/scoreboard/str)
call stack:
/scoreboard/str (/scoreboard/str): sortScores()
Spunky_Girl (/mob): add score()
You need to set up your list like so:
var/list/scores = list(m.number.value,m.name,world.timeofday)
When sorting your scores, you need to interpret your list with the knowledge that every three elements is one block of values, and increment accordingly.
In addition, don't define variables inside of loops if it can be avoided. It leverages extra opcodes onto the virtual machine, which can be avoided. It's best to identify variables outside of the main loop's jump blocks.