ID:174031
 
mob/verb/ContentCopy(obj/o in world,obj/c in world)
c.contents += o.contents

The contents from o.contents dissappear when I try setting c.contents to o.contents.

What I am trying to do it towhere I can have o.contents copied and sent over c.contents, But I cannot think of a way how. Anyone have an solutions as to how I can fix this?
Texter wrote:
mob/verb/ContentCopy(obj/o in world,obj/c in world)
c.contents += o.contents

The contents from o.contents dissappear when I try setting c.contents to o.contents.

What I am trying to do it towhere I can have o.contents copied and sent over c.contents, But I cannot think of a way how. Anyone have an solutions as to how I can fix this?

The reason this is happening is because the contents are being moved, not copied. Try the following:
mob/verb/ContentsCopy(obj/O in world, obj/C in world)
C.contents += O.contents.Copy()
In response to Malver
It still seems to repeat the same problem, Takeing the contents away from o.

mob/var/list/Copy= list()
mob/verb/CopyTest(obj/o in world)
if(istype(o,/obj/Folder))
var/obj/Folder/s = new/obj/Folder
s.icon= o.icon
s.name= o.name
s.stat= o.stat
s.contents += o.contents.Copy()
usr.Copy +=s
return()

I am going to go look up Copy(), Never heard of its use before, Maybe I can just copy the entire object instead of going by the method I am now.

*Edit*
I can't seem to find any information on the Copy() proc that will help copy the entire object, I am still getting the repeadiate problem on losing o's contents. Anyone know of a method that will go along better then how im doing now?
In response to Texter
Make a var and set it to s and then use it to do the contents then it wont matter if the contents get removed cause its not the real s just delete it at the end of the function.
In response to Texter
Texter wrote:
<s>mob/var/list/Copy= list()</s> //What's this for?! Get rid of it. =)
mob/verb/CopyTest(obj/o in world)
if(istype(o,/obj/Folder))
var/obj/Folder/s = new/obj/Folder
s.icon= o.icon
s.name= o.name
s.stat= o.stat
for (var/obj/Obj in o)
var/ObjCopy=new Obj.type(s)
ObjCopy.name=Obj.name
ObjCopy.icon=Obj.icon
//Copy all the other vars that you want

Edited parts in bold.
In response to Crispy
mob/var/list/Copy= list() is there so the user can pastes the objects stored in there to an objects contents of his choice. By doing

mob/verb/Paste(obj/O in world,obj/C in usr.Copy)
O.contents+= C

In response to Malver
Malver wrote:
The reason this is happening is because the contents are being moved, not copied. Try the following:
mob/verb/ContentsCopy(obj/O in world, obj/C in world)
C.contents += O.contents.Copy()

This won't work because list.Copy() is not a deep copy; it only copies references, not the objects themselves. So by adding the copied references to C.contents, the items still move.

I'd try a different tactic.
atom
proc/Copy(newloc)
var/atom/A = new type(newloc)
for(var/V in vars)
if(V != "loc" && vars[V] != initial(vars[V]))
A.vars[V] = vars[V]
return A

mob/verb/ContentsCopy(obj/O in world, obj/C in world)
for(var/obj/item in O)
item.Copy(C)

Lummox JR
In response to Lummox JR
untime error: Cannot write to atom.verbs.
proc name: Copy (/atom/proc/Copy)
usr: Texter (/mob)
src: the gfddfgf (/obj/Sheet)
call stack:
the gfddfgf (/obj/Sheet): Copy(the gfddfgf (/obj/Sheet))
Texter (/mob): Paste(Folder (/obj/Folder), the gfddfgf (/obj/Sheet))
I get this runtime error when I do this, And everything seems to work somewhat, Though I cannot paste the same object twice inside of the contents, I also have noticed when I copy an object it will sometimes disappear completly.
Example: Lets say I go through an objects contents and Copy one of its objects *via Copy verb*, Now when I try to paste the new object, It disappaers completly from the contents from whence it was originly leaving the pasted item at it's destination.

mob/var/list/Copy= list()

mob/verb/CopyTest(obj/o in world)
usr.Copy +=o

mob/verb/Paste(obj/o in world,obj/C in usr.Copy)
for(var/obj/item in usr.Copy)
item.Copy(C)
o.contents += item
In response to Texter
Texter wrote:
runtime error: Cannot write to atom.verbs.

There are certain vars which can't be written to; type and verbs to name but two. You might also want to exclude contents and vars.
In response to Texter
Okay, it seems I overlooked a couple of issues. Let's try changing that Copy() code.
atom
proc/Copy(newloc)
var/atom/A = new type(newloc)
for(var/V in vars)
if(vars[V] == initial(vars[V])) continue
switch(V)
if("loc") continue
if("contents")
for(var/obj/O in src)
O.Copy(A) // recursive deep copy
if("verbs")
for(var/vb in verbs)
// theoretically, default verbs shouldn't be removed
// but others can be added
if(!(vb in A.verbs))
A.verbs += vb
else
// note: any other lists besides contents will not be deep-copied
if(istype(vars[V], /list))
var/list/L = vars[V]
A.vars[V] = L.Copy()
// any more references will also not be copied
else
A.vars[V] = vars[V]
return A
To force deep-copying or reference copying for certain items, or make other adjustments, you'll have to override Copy() to do it.
obj/stone
var/list/neighbors

New()
GetNeighbors()

proc/GetNeighbors()
if(neighbors) neighbors.Cut()
else neighbors = new
for(var/obj/stone/S in oview(1, src))
neighbors += S

Copy()
var/obj/stone/S = ..()
S.GetNeighbors()

Lummox JR