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
ID:168703
![]() Sep 7 2005, 2:55 pm
|
|
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) 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 |
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 |
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. |
Copy_Object(obj/O in view())//for someone to summon something they built. This is the verb. |
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