ID:168703
 
How do i make a verb so i can copy the object and all of its vars as if was exactly the same thing? I want the verb to create the objects with all of its vars and leave it where it is then make the object go to my location.

-Killa E
You just simply copy the vars. :o

mob/verb/copy(atom/A in view(src))
var/atom/N = new A.type (A.loc)
var/list/denyvar = list("client","key","loc","x","y","z","type")
// list of variables which shouldn't be changed
for(var/i in A.vars)
if(i in denyvar) continue
// don't copy variables which can effect the object in a way we don't want to
N.vars[i] = A.vars[i] // set the variable of "A" to the new atom's var


I might have forgotten some variables which shouldn't be changed, so you can add them to the list if I forgot any.

~~> Dragon Lord
In response to Unknown Person
Its strange that you decided to deny those variables,since a CarbonCopy is an Exact duplicate I suggest leaving the burdens of variables such as 'key' and 'client' on the shoulders of the programmer himself.
(Such is a prefrence of mine,but I prefer to let the compiler (on a limited scale) choose which vars to copy)
proc/itc_CcObj(modelObj)
{
var Cc=new modelObj.type;
var VarName;
for(VarName in modelObj.vars)
{
if(issaved(model.vars[VarName]) && VarName!="key")
{
Cc.vars[VarName]=modelObj.vars[VarName];
};
};
return (Cc);
};


Itanium

In response to Itanium
The reason I deny those variables to be copied is because when you set another mob's key to a person already existing, their mob will immediatly change to possess the new object. Same with client. I only denied x,y,z, and loc because the person might want to create it somewhere else.

And as you said, it's up to the programmer so he can add/remove some things him or herself if they want to, so they can do whatever they want, anyway.

~~> Dragon Lord
Please explain it a little better. I dont understand.
In response to Y2kEric
I'll do it in chunks.

mob/verb/copy(atom/A in view(src))


We define a new verb which mobs can click, and do to any object in your screen. Simple.

  var/atom/N = new A.type (A.loc)


This is how we create the new "carbon copy". we create it and set it to a variable, so we can access it. The (A.loc) is where you want to create it.

  var/list/denyvar = list("client","key","loc","x","y","z","type")


This is a list of variables which we do not want to copy. You can put in or take out any of them, if you want to.

  for(var/i in A.vars)


This loops through every single variable the object we're copying has.

    if(i in denyvar) continue


The if() statement pretty much checks if the variable is in the denyvar list. Sounds like english.

When we are in a loop, the <code>continue</code> statement just loops to the end of the loop. It doesn't quit the loop, but goes to the next item.

    N.vars[i] = A.vars[i]


Since the vars variable is an associative list, we can access the information the variable by using square brackets.

<code> var/list/L = list("this"=5,"is"=8,"a"=2,"test"=12") // an associative list looks like this. Data can be stored inside an element of the list src << L[1] // if you put a number, it takes the number element, (1 is the first element, 2 is the second, etc) src << L["is"] // if we know what the element is, it will return the data that is in the element. </code>

This should output:
<code> 5 8 </code>

Back to the programming, since the type path of the copy object, and the new carbon copy are the same, we can loop through both and assume the variables both exist.

~~> Dragon Lord
In response to Unknown Person
Thx for breaking it down but one more question.
When i change atom to obj it gives me this:
runtime error: Cannot write to datum.parent_type.
proc name: Copy Object (/mob/verb/Copy_Object)
source file: Main.dm,183
usr: Y2kEric (/mob/Player)
src: Y2kEric (/mob/Player)
call stack:
Y2kEric (/mob/Player): Copy Object(Stereo2 (/obj/objects/Stereo2))

but it still copies it fine.
In response to Y2kEric
Copy_Object(obj/O in view())//for someone to summon something they built.
set category = "Objects"
Turf_Check()
if(!O) return
if(usr.build)
if(O.owner=="[usr.key]")//if the usr is the owner of the object.
var/obj/copy_o = new O.type (usr.loc)
var/list/denyvar = list("client","key","loc","x","y","z","type")
for(var/V in O.vars)
if(V in denyvar)
continue
else
copy_o.vars[V] = O.vars[V]
return
else if(O.owner != "[usr.key]") usr<<"<b>You are not the owner of [O].</font>"
else
return

This is the verb.
In response to Y2kEric
Thankx for you help, i fixed the problem.