ID:139989
 
Code:
#define islist(X) istype(X, /list)

database
var
keys = list()

proc
process_account(mob/M)
if( !(M) )return
if( !(M.ckey in keys) )
keys += M.ckey
keys[M.ckey] = list("Ips" = list(), "Ids" = list())
keys[M.ckey]["Ips"] += M.client.address
keys[M.ckey]["Ids"] += M.client.computer_id

if( !(M.client.computer_id in keys[M.ckey]["Ids"]) )
keys[M.ckey]["Ids"] += M.client.computer_id

if( !(M.client.address in keys[M.ckey]["Ips"]) )
keys[M.ckey]["Ips"] += M.client.address

link_accounts(mob/M)
if( !(M) )return
var/html = null
for(var/a in 1 to length(database.keys) ) if( database.keys[a] != database.keys[M.ckey])
for( var/i in 1 to length(database.keys[M.ckey]["Ips"]) )
for( var/r in 1 to length(database.keys[a]["Ips"]) )
if( database.keys[M.ckey]["Ips"][i] in database.keys[a]["Ips"][r])
html += " <b><font color = red>[M.ckey] and [database.keys[a]] are associated<br>"

if( html == null)
html += " No one is associated with this person."
return html


Problem description:

I get the following runtime error on line 27.

runtime error: bad index
proc name: link accounts (/database/proc/link_accounts)
source file: Admin.dm,27
usr: Axerob (/mob)
src: /database (/database)
call stack:
/database (/database): link accounts(Axerob (/mob))
Axerob (/mob): SHOW(Axerob (/mob))


Line 27 happens to be: for( var/r in 1 to length(database.keys[a]["Ips"]) )

Now I know perfectly well what this runtime means and stuff, but i'm not sure WHY it's happening.

Here is the bit of text I grabbed in the savefile, to make sure that everything was saving properly,and it is.

database = object(".0")
.0
type = /database
keys = list("axerob" = list("Ips" = list(null,"127.0.0.1"),"Ids" = list("1341379675")),"tehrockz0r" = list("Ips" = list("127.0.0.1"),"Ids" = list("1341379675")))
names_database = list()

Now, I can easily grab the list of Ip's and ID's when it's [M.ckey], but I get that error when it's [a], or anything else other than [M.ckey].

I've also checked to see if [a] was a list each time, and it's returning 0(So The database.keys[a] is not showing up as a list, but database.keys[M.ckey] is detected as one)

I've also interchanged who M was(Both ckeys "axerob" and "tehrockz0r" work, it's just when referencing the other is wwhen it breaks.)

I'm really stumped on this one, Unless I'm overlooking something, I think this might be a BYOND Bug? Not sure.
for(var/a in 1 to length(database.keys) )
length(database.keys[M.ckey]["Ips"])
length(database.keys[a]["Ips"])

a is a number. M.ckey is a string.

database.keys["[some_key]"] is giving you the second list, database.keys[some_number], if I remember right, will give you one of the string indexes.

So what you probably want is to change that first for loop to: for(var/a in database.keys) which will give you the string indexes directly.
In response to Destroy
Destroy wrote:
for(var/a in 1 to length(database.keys) )
length(database.keys[M.ckey]["Ips"])
length(database.keys[a]["Ips"])

a is a number. M.ckey is a string.

database.keys["[some_key]"] is giving you the second list, database.keys[some_number], if I remember right, will give you one of the string indexes.

So what you probably want is to change that first for loop to: for(var/a in database.keys) which will give you the string indexes directly.

Of course that fixes it, I can't believe I overlooked that option. After modifying the code a little bit, I get a result.

"axerob and /list are associated"

        link_accounts(mob/M)
if( !(M) )return
var
html = null
for(var/a in database.keys) if( database.keys[a] != database.keys[M.ckey])
for( var/i in 1 to length(database.keys[M.ckey]["Ips"]) )
if( database.keys[M.ckey]["Ips"][i] in database.keys[a]["Ips"])
html += " <b><font color = red>[M.ckey] and [database.keys[a]] are associated<br>"

if( html == null)
html += " No one is associated with this person."
return html


Now how to i get that /list to go away, and be replaced with the actual name of the string?
In response to Axerob
In this case, wouldn't a already be the key itself?

database.keys[a] != database.keys[M.ckey]

[M.ckey] and [database.keys[a]]
In response to Destroy
I figured it out, thanks for your help Kobata.