ID:262213
 
Code:
                //What Species?
ans=input("What species would you like?") in list("Human", "Mutant", "Genie", "Int Insect")
var/attrolls[6]
species = ans
switch(ans)
if("Human")
for(var/i = 1; i<=6; i++)
attrolls[i]=roll("3d6")

if("Mutant")
for(var/i = 1; i<=4; i++)
attrolls[i]=roll("3d6")
attrolls[5]=roll("5d6")
attrolls[6]=roll("1d6")

if("Genie")
for(var/i = 1; i<=4; i++)
attrolls[i]=roll("3d6")
attrolls[5]=roll("4d6")
attrolls[6]=roll("2d6")

if("Int Insect")
for(var/i = 1; i<=6; i++)
if(i<=3) attrolls[i]=roll("4d6")
else attrolls[i]=roll("2d6")

//What race?

var/list/attrl = dd_sortedObjectList(attrolls)


Problem description:

The above code generates 6 attribute scores depending on species chosen. I need to sort those scores, and I am trying to use Deadron's List lib. I make the call to dd_sortedObjectList with a list I know contains the numbers (I ran a for loop once just to make sure) At runtime, I get the following error:

runtime error: Cannot execute null.dd SortValue().
proc name: dd sortedObjectList (/proc/dd_sortedObjectList)
source file: List.dm,73
usr: Neo Skye (/mob/player)
src: null
call stack:
dd sortedObjectList(/list (/list))
Neo Skye (/mob/player): Topic("createchar", /list (/list))

am I using the list wrong? is this a bug with the lib? any help is much appreciated.
You're using the library wrong. It is only meant to sort objects or mobs, not numbers. That's why it gives you this error. It's trying to call a proc belonging to the value of one of the items in your list, which it assumes to be an object. Yours are numbers, which have no procs. That's where the null value is coming from, your number. It shouldn't be too hard to make a sorting proc for numbers. You could probably do it in a few lines of code. Perhaps Deadron will add in a function for numerically sorting lists.

~X
You've also got a problem in the way you're using loops.

Wrong:
for(var/i = 1; i<=4; i++)
attrolls[i]=roll("3d6")
attrolls[5]=roll("5d6")
attrolls[6]=roll("1d6")


Right:
for(var/i = 1; i<=4; i++)
attrolls[i]=roll("3d6")
attrolls[5]=roll("5d6")
attrolls[6]=roll("1d6")


You don't need to assign 5 and 6 during the loop, since they have nothing to do with it. Do them after the loop.

Lummox JR
In response to Xooxer
Awesome. Perfect. I am up and running! I wrote a quick proc to do the job. It's no binary sort like the lib, but it's not too bad, and it gets the job done.

Here it is:

proc/sortNumbersList(list/pre_sorted)
var/list/post_sorted = new()
var/current_placement

for(var/current_number in pre_sorted)
if(post_sorted.len>0)
current_placement = 1
while(current_number<post_sorted[current_placement])
current_placement++
if(current_placement>post_sorted.len) break
post_sorted.Insert(current_placement, current_number)
else
post_sorted.Add(current_number)
return post_sorted


BTW, Thanks for catching the typo in the for loops. Much more clean and efficient.