ID:149360
 
I seem to be having some trouble with multidimensional lists. Im getting bad index errors, nomatter what I do. This is basically what im trying to do :



list[][]

list += "[some_var]:[some_other_var]"
list["[some_var]:[some_other_var]"]["stuff"] = 5
list["[some_var]:[some_other_var]"]["other_stuff"] = 10

I've tried many variations of that, and this is the most recent one:

var/name = "[type]:[time]"
logs += name
var/list/sublist
sublist = logs["[name]"] // This is the erronous line
sublist["time_stamp"] = "[time]"
sublist["owner"] = "[owner]"
sublist["target"] = "[target ? target : "none"]"
sublist["extra"] = "[extra ? ": [extra]" : ""]"
sublist["type"] = "[type]"
logs["[name]"] = sublist

And this is the error:

runtime error: bad index
proc name: MakeLog (/LOGCONTROL/proc/MakeLog)
source file: Admin System.dm,189
usr: Alathon (/player/New_Char)
src: /LOGCONTROL (/LOGCONTROL)
call stack:
/LOGCONTROL (/LOGCONTROL): MakeLog("shutdown", Alathon (/player/New_Char), null, null)
Log("shutdown", Alathon (/player/New_Char), null, null)
Alathon (/player/New_Char): ShutDown(10)

I seem to be completely missunderstanding something, or doing something totally and utterly wrong. Any help would be appreciated.

Thanks,
Alathon
Alathon wrote:
I've tried many variations of that, and this is the most recent one:

var/name = "[type]:[time]"
logs += name
var/list/sublist
sublist = logs["[name]"] // This is the erronous line
sublist["time_stamp"] = "[time]"
sublist["owner"] = "[owner]"
sublist["target"] = "[target ? target : "none"]"
sublist["extra"] = "[extra ? ": [extra]" : ""]"
sublist["type"] = "[type]"
logs["[name]"] = sublist

And this is the error:

runtime error: bad index
proc name: MakeLog (/LOGCONTROL/proc/MakeLog)
source file: Admin System.dm,189
usr: Alathon (/player/New_Char)
src: /LOGCONTROL (/LOGCONTROL)
call stack:
/LOGCONTROL (/LOGCONTROL): MakeLog("shutdown", Alathon (/player/New_Char), null, null)
Log("shutdown", Alathon (/player/New_Char), null, null)
Alathon (/player/New_Char): ShutDown(10)

"Bad index" is a nebulous error DM throws when the item being indexed is supposed to be a list, but isn't; it's either a non-list or it's null.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
"Bad index" is a nebulous error DM throws when the item being indexed is supposed to be a list, but isn't; it's either a non-list or it's null.

Lummox JR

Reading that made me realize the problem. Thanks :)

Alathon
In response to Alathon
Alathon wrote:
Reading that made me realize the problem. Thanks :)

Glad I could help. Personally I wish the bad index error said what it really means: "Invalid list".

Lummox JR