ID:2143635
 
(See the best response by Ter13.)
Code:
var/turf/build_turfs = list("floor" = /turf/floor, "wall" = /turf/wall)

turf
icon = 'turfs.dmi'

floor
icon_state = "floor"

wall
icon_state = "wall"
density = 1

mob
verb
build_turf()
//There is a whole bunch of code here that asks what type of turf
//and where you want to create it, basically in the end we have
//x, y, z and turf type.

var/x_pos = 1
var/y_pos = 1
var/z_pos = 1
var/turf_type = "floor"

var/area/new_area = locate(x_pos, y_pos, z_pos)
var/turf/new_turf_type = build_turfs[turf_type]
var/turf/new_turf = new new_turf_type.type

new_area.contents += new_turf


Problem description:
My goal is to have a list of turfs that the player is allowed build, which is the build_turfs var but when ever the player uses that verb nothing happens. No turf is created and no errors are outputted.

Any ideas?
The way turfs work is a bit strange at runtime, instead of adding the turf to the area.contents list, you'd want to pass locate(x,y,z) through New()
var/turf/new_turf = new(locate(x_pos,y_pos,z_pos))


You're not actually creating a new turf, you're making the turf at that position change into the turf you're "creating", as there's only ever really one turf on a tile at any given time.
Best response
mob
verb
build_turf()
//There is a whole bunch of code here that asks what type of turf
//and where you want to create it, basically in the end we have
//x, y, z and turf type.

var/x_pos = 1
var/y_pos = 1
var/z_pos = 1
var/turf_type = "floor"

var/new_turf_type = build_turfs[turf_type]
new new_turf_type(locate(x_pos,y_pos,z_pos))


Turfs can't be created*, destroyed*, or moved. When you create a new turf, what you are actually doing is changing one turf's members into another turf prototype's members.

* = there is an exception to this rule when you change the world.maxx, world.maxy, or world.maxz variables. Turfs are created or destroyed when you do this, but using new or del on a turf doesn't actually create or destroy the turf. You can create off-map turfs too, but they don't seem to register properly as turfs and can't be relocated or displayed except in grids and statpanels.

When you use new() on a turf, you HAVE to supply the old turf that you are replacing as the first argument of the initializer.
Ah I see thanks for the help :)