ID:264932
 
Code:
mob
verb
Test(msg as text,num as num)
var/getin = new/list("[msg] {name=msg;power=num;}")
for(var/T = 0, T<100, T++)
if(testlist[T["power"]]>num)
continue
else
testlist[T] += getin
var/list
testlist[100]


Problem description:

Okay, so I suck at lists, I'm trying to make it so when I add a name and power amount, it will order itself in the list from strongest to weakest with no more than 100 entries.

With the code above, I get a runtime error:

runtime error: bad index
proc name: Test (/mob/verb/Test)
source file: Arrancar.dm,7
usr: Guest-1450962619 (/mob)
src: Guest-1450962619 (/mob)
call stack:
Guest-1450962619 (/mob): Test("Name One", 100)


I'm not even sure if this is even close to what I am meant to do to order the list like that lol. I fail when it comes to lists. :/
The max index would be 99 in this case, not 100, since it starts with 0.
In response to KingCold999
KingCold999 wrote:
The max index would be 99 in this case, not 100, since it starts with 0.

Yeah that's fine, 0-99 is okay lol.
In response to Liam Howe
Your input showed 100 though, which is why you got the index error (looking for index 100 when it stops at 99) :P
In response to KingCold999
Changed it and I get the same error.
if(testlist[T["power"]]>num)


This is the line the runtime error happens apparently.
Still having this problem, anyone know were I'm going wrong?
In response to Liam Howe
In DM, list indices are 1-based, not 0-based. You want 1 - 100.

Also, it looks like your making a list of lists. You would be better off making a single associative list instead where "[name]" = power.
In response to DarkCampainger
mob
verb
Test(msg as text,num as num)
//var/getin = new/list("[msg] {name=msg;power=num;}")
if(testlist.len <= 100)
testlist.Add(msg)
testlist[msg] = num
Test2()
for(var/T in testlist)
src << "[T] = [testlist[T]]"
var/list
testlist = new/list()


Something like this? (Dunno if this is what you wanted, try it out)

It could use some work (to make sure there's no duplicate entries and such)
In response to KingCold999
KingCold999 wrote:
> mob
> verb
> Test(msg as text,num as num)
> //var/getin = new/list("[msg] {name=msg;power=num;}")
> if(testlist.len <= 100)
> testlist.Add(msg)
> testlist[msg] = num
> Test2()
> for(var/T in testlist)
> src << "[T] = [testlist[T]]"
> var/list
> testlist = new/list()
>

Something like this? (Dunno if this is what you wanted, try it out)

It could use some work (to make sure there's no duplicate entries and such)

Sort of, I actually want the list to get ordered by the amount of power, with 1 being the strongest.
In response to Liam Howe
So the number is the order they fall into?
In response to KingCold999
KingCold999 wrote:
So the number is the order they fall into?

Yeah, so the list will go


Strongest, 2nd strongest, 3, 4, 5, etc....

All the way upto 100.

When the "usr" is added to the list, I want it to add them in the correct place in that list, if that's possible.


The idea is to making a ranking system based on power. Strongest being rank one all the way upto 100. And once a new player enters the game and becomes a certain "race", they will be given a rank based on how powerful they are.
In response to Liam Howe
Liam Howe wrote:
KingCold999 wrote:
So the number is the order they fall into?

Yeah, so the list will go


Strongest, 2nd strongest, 3, 4, 5, etc....

All the way upto 100.

When the "usr" is added to the list, I want it to add them in the correct place in that list, if that's possible.


The idea is to making a ranking system based on power. Strongest being rank one all the way upto 100. And once a new player enters the game and becomes a certain "race", they will be given a rank based on how powerful they are.


So... like a highscore system? (Sorry if thats not it.. I'm a bit confused right now on what this is going to accomplish lol)
In response to KingCold999
Yeah, like a scoreboard system. Only difference being the user will get a rank "Rank [number]". If someone passes someone else in power, the users rank will be updated accordingly.
In response to Liam Howe
So its a list of users sorted by their "power level" and given ranks accordingly?