ID:157595
 
I have the code:
New()
contents = new("Iventorio" = list(), "Equipamento" = list())

But when I use "usr.contents["Iventorio"] += object", into the Click() proc of the object,the game runs,but if i click, appear this error in the Output:

runtime error: bad index
proc name: Click (/obj/equipament/armor/Click)
usr: Guest-3804674167 (/mob)
src: Armadura Arshal (/obj/equipament/armor/Armor1)
call stack:
Armadura Arshal (/obj/equipament/armor/Armor1): Click(Grama (6,5,1) (/turf/Grama), "Default.Mapa Principal", "icon-x=24;icon-y=11;left=1;scr...")


I want to know how-to do it, create a list into contents, i need this, for when i use usr.contents["Iventorio"], the object go to the list, instead of create a copy of it.
Well without the code you were using to generate the runtime error(at least thats the way I read it) I think your looking for something like this:

Click()
src.loc = locate(usr.contents)



That would move the clicked object into the contents of the usr that clicked on it.
Problem #1: contents = new(...)
This is improper use of list/New. The arguments for list/New() refer to the dimensions of the list. What you want is list(), not new(). At this point, I can only assume you haven't read the DM guide, or atleast not the part about lists. That, or it was an accident. In which case, now you know.

var/list/cake = new(1,2,3) == var/list/cake[1][2][3]

Problem #2: contents = list("this isn't an atom")
The contents list is a very special list in that it can contain only one thing: movable atoms. Nothing else. With a little bit of research, you could have easily found that out, as it is stated very clearly in the "contents" reference entry.

EDIT: just to clarify, "movable atoms" refers to atoms of the type /atom/movable, which pretty much translates to the /mob and /obj types.

Problem #3: contents = list("this isn't an atom" = list())
What you are refering to, "creating a list into contents," is attempting to turn the list into a dictionary and associating the entries with lists. This is just another one of those things that you cannot do with the contents list.

tl;dr:
a) you're using the wrong function
b) you can't put non-movable atoms into contents
c) you cannot associate entries in the contents list

Not to sound like a dick, but you have actually failed I think on every possible level here. But don't worry, it's an easy fix, and one you should remember. Do not use the contents list for anything other than the contents of your atom. Create a new list if it's necessary, because they serve absolutely 0 purpose being entries in the contents list.

EDIT: placing atom A into atom B's contents literally moves atom A into atom B. It even sets atom A's "loc" to atom B. It does not "make a copy of it."

Have a nice day.
In response to Jotdaniel
The atom variable loc refers to the atom that the atom is located "inside" of. locate() is not necessary whenever you want to set loc. A lot of newbies have this misconception, so I'll clear it up for you.

If you looked in the reference, you will see all of the proper uses of locate(). It can locate a turf on the map using x,y,z coordinates, it can locate an atom with a tag, it can locate an atom with a reference string, and it can locate an atom of a specific type. What you have, locate(usr.contents), means nothing. There is nothing to locate. It's just a list.

Maybe what you wanted was simply src.loc = usr.contents, but that isn't right either, though honestly it seems like it might make sense. What you want is src.loc = usr. You want to say "we are located inside of <this atom>. src.loc = usr.contents more translates to "we are located inside of <some list>," which doesn't tell us much about where he's located at all (how can we figure out who owns that list?).
In response to Keeth
Keeth wrote:
Maybe what you wanted was simply src.loc = usr.contents, but that isn't right either, though honestly it seems like it might make sense. What you want is src.loc = usr. You want to say "we are located inside of <this atom>. src.loc = usr.contents more translates to "we are located inside of <some list>," which doesn't tell us much about where he's located at all (how can we figure out who owns that list?).

This part is not that great of an explanation.

The loc of something is the atom which it is located in. A list is not an atom.
In response to Keeth
I'm also at work, so pardon me for a mistake here or there. Please don't ramble in explanations.
Thank you all, but yes: I read the guide on the lists (I am currently in the SaveFile), and I thought, that contents can not be used with other lists inside. But I tried to do this, because no one has solved the problem of my other topic, I wanted to know how to put an object into a list. This topic has already been resolved, but if possible help me with my other questions:

obj/equipament
Click()
usr.items += src


I did it for when you click the item, go to the inventory. When I click, it goes to the inventory, but the item still in the ground. Then I thought: "It must be a copy. If it is a copy, just delete the original! I will add a "del(src)" to delete the original." But now that I put, when I click, the copy is also deleted, not just the original ... Please help me, I need to create a system of take and drop, but I do not want do this with the usr.contents ... Thanks ...
In response to Twinsen99
Again, the loc of an atom is some other atom. Adding it to a list stores a reference to the object, not the object itself. You should move the item to contents as normal, and then ALSO add it to the items list.
In response to Garthor
thanks, I finally did it! thanks to you, and of course, God also ...