ID:264926
 
Code:
turf
icon = 'base.dmi'
Click()
new usr.build_type (locate(src.x,src.y,src.z))


Problem description:
usr.build_type holds a reference to an obj. When I click on a turf, it gives me a runtime error. (Cannot create objects of type /obj.)

How do I create new copies of build_type?
show me whole code connected to build_type proc
In response to Hassanjalil
That's all the code. build_type contains a reference to an object created during runtime.

I'm thinking I have to create a blank object and give it the properties of the object referenced by build_type.
I always had to just create a blank obj and appropriate each variable manually (var/obj/O = new, O.name = build_type.name, etc). There probably is a way though but I never figured it out.
build_type is not a type, it is an instance of an object. To create an object, you need a type path.

The type of an object is stored in its type variable.

Also: locate(src.x, src.y, src.z) is quite pointless. That gives you the turf at the coordinates that are the same as the turf you just clicked on, which happens to be... the turf you just clicked on. Just use "src" instead.
In response to Garthor
I'm trying to copy a particular instance of an object that was created during run-time. I assume I just need to assign the variables of the referenced object to a blank object?
In response to Warlord Fred
When you're defining the build_type var with an object, assign it the ".type" variable of the object.

What i mean is: When you do "var/a = new /obj/Wall(src)", a isn't /obj/Wall, its the one instance of the wall that you created. So you can't later do "new a(src)" because a isnt a path. Which is whats giving you the runtime error. Atleast i think thats why you get the runtime error, going off what Garthor said and what the reference says. Heres how i would do it:

var/build_type
world
New()
..()
CreateStuff()
proc/CreateStuff()
if(prob(90))
var/obj/a = new /obj/Wall(locate(2,1,1))
build_type = a.type
obj
Wall
density = 1
icon = 'Wall.dmi'
turf
Grass
icon = 'Grass.dmi'
Click()
new build_type(src)
In response to Turles
I'm trying to get a copy of the object referenced by build_type, including any custom icon or name the object may have. Creating a new type of the object will not preserve that.
In response to Warlord Fred
This might be able to help you
In response to Warlord Fred
Warlord Fred wrote:
I'm trying to get a copy of the object referenced by build_type, including any custom icon or name the object may have. Creating a new type of the object will not preserve that.

This snippet should be able to help you:
http://www.byond.com/members/Jtgibson/forum?id=36

Just remember to move the new copy to the location you want.
In response to Warlord Fred
Yeah i don't think its possible to do that. There is a vars var i think but from what i read it has literally everything so copying that over might be too much. I don't like the idea of defining the objects variables inside the process that creates it though, sounds like it might be a pain later on if you wanted to add new processes of creation. It also probably looks very cluttered which will make it annoying to edit later on.

There is probably a better way but id approach it something like this:

var/BuildType
var/list/Buildables= list("Wall" = /obj/Creatables/Wall, "Ball" = /obj/Creatables/Ball)
var/list/BuildTypeDesc = list("Name","Icon")

mob/verb/BuildWhat()
var/structure_name = input(usr, "Build what") as null|anything in Buildables
BuildTypeDesc["Name"] = input("Name?") as text
BuildTypeDesc["Icon"] = input("What icon") as null|icon
BuildType = Buildables[structure_name]

obj/Creatables
New(N = BuildTypeDesc["Name"],I = BuildTypeDesc["Icon"])
..()
if(N) src.name = N
if(I) src.icon = I
Wall
Ball

turf/Click()
if(!BuildType) return
var/obj/O = new BuildType()
O.loc = src