ID:142387
 
Code:
            Effect(Chip/C)
if(istype(C))
if(!C.bonus)C.bonus=new
if(!C.bonus["damage"])C.bonus["damage"]=C.damage
C.damage+=damage


Problem description:
I always seem to be getting a bad index error at this part:
C.bonus["damage"]=C.damage

What am I doing wrong? According to the DM Reference, this is perfectly valid (and the non-redundant way of making list associations). The bonus list is always going to be initialized due to the line above it. So why am I getting a bad index error?
How have you declared 'bonus' for your Chip datum? If it's not something like var/list/bonus or var/bonus[] then DM will yell at you if you try to do list stuff(like make an association) for non-list stuff.
In response to tenkuu (#1)
It's defined as: Chip/var/list/bonus. So no problem there.
In response to Kakashi24142 (#2)
I believe that the problem is actually before the part you think it is:
if(!C.bonus["damage"])

Since the line above initates the list, "damage" is not within the list (and as it is looking for "damage"'s entry for the value, and cannot find it, it results in the said error).

I'm just assuming, so just in case, I recommend you try changing the line shown to
if(!("damage" in C.bonus))
When you assign the value afterwords, "damage" will be added to the list.
In response to GhostAnime (#3)
The way you said me to change it to is the way I had it before lol. So I'm quite sure it's the line I mentioned is the one that's causing it.
In response to Kakashi24142 (#2)
Then it's something else related since the following code works for me. It'll output 450.
Chip
var/list/bonus
var/damage

var/Chip/C
mob/verb/hrm()
C = new
what(C)

mob/proc/what(Chip/C)
if(istype(C))
C.damage += 450
if(!C.bonus)C.bonus=new
if(!C.bonus["damage"])C.bonus["damage"]=C.damage
world << C.bonus["damage"]
In response to Kakashi24142 (#4)
If the list is never initialized, you will get an error when you try to assign a value to the list.

Did you ever initialize the list? (IE var/list/my_list=new())
In response to Jmurph (#6)
I was thinking the samething earlier but noticed the line above
if(!C.bonus)C.bonus=new
In response to GhostAnime (#7)
You are correct. I also get no error when the code as posted by tenku is run, so the error must be elsewhere. I suspect in the OPs code there is no such initialization or the list is being nulled out elsewhere. Perhaps the check is spitting the error (if there is no list a check for an indexed value from that list will return an error, IIRC).
In response to Kakashi24142 (#2)
Youd code will initialize the list properly if it's null, so I would say the list is not null, nor is it a list, by the time it reaches here. Some other routine, possibly a load from a savefile, is overwriting its value with something inappropriate.

Lummox JR