ID:1871497
 
(See the best response by Kaiochao.)
Code:
mob/var/building = 0
mob/var/tmp/turf/buildselection
client/North()
if(usr.building)
var/turf/A=new usr.buildselection(locate(usr.x,usr.y,usr.z))
A.owner=usr.name
player_turfs+=A
mob.Input_move(NORTH)

This is the code that happends, when you click on a turf, that'll appear in a seperate tab.
obj/build
Click() if(usr.buildon)
builtobjects+=1
if(savetype=="/turf/build/Roof1")
var/turf/A=new/turf/build/Roof1(locate(usr.x,usr.y,usr.z))
A.owner=usr.key
player_turfs+=A
usr.buildselection = A
usr.building = 1


Problem description:
Basically, I've been trying to do various things with my code, just like seen in Dragon Universe or various Custom Games. I've been trying to make it so, the code places the directory of a turf or etc. when clicked on , in a variable. Then when you move, and if a certain Variable == 1, You place a block depending on the directory that was stored in the variable. Please look above for further things.
Does anyone know how to make this work ?
Best response
The "new" operator takes a type path, not an object instance. When you're setting usr.buildselection = A in Click(), 'A' is a new instance of /turf/build/Roof1 that is placed at usr's coordinates. You probably shouldn't even be making it there in the first place.

When you say "directory of a turf" you probably mean "type". An example of a type is /turf/build/Roof1. An instance would be new /turf/build/Roof1. They're very different and you can't treat them the same way.

So, what you probably want is something like this:
obj/build
Click() if(usr.buildon)
builtobjects++

// You might want to use this instead, to avoid repeating yourself.
// I don't know how you're setting savetype, but it's possible that
// this turns out to be null if savetype isn't an actual type.
usr.buildselection = text2path(savetype)

usr.building = TRUE

// You can use Move() to handle things that happen "on player movement input"
// It's is called by North(), South(), etc. by default, so you don't have
// to copy/paste this stuff.
client/Move(Loc, Dir)
// You might not even need 'building' if 'buildselection' being non-null means you're building
if(usr.building && usr.buildselection)
var/turf/A = new usr.buildselection (usr.loc)
A.owner = key // is it name or key?
player_turfs += A

usr.Input_move(Dir)
In response to Kaiochao
Thanks alot, that is actually helpful. Could you midn explaining the usr.buildselection = and builtobjects ++ in more depth please because, I think, I'm going to learn alot about this.

Thanks ^.^
In response to Kaiochao
for some strange reason, the savetype is giving me errors.
loading Reichibi.dme
loading Interface.dmf
System Coding\(0.9.9) Building.dm:8:error: savetype: undefined var
System Coding\(0.9.9) Building.dm:18:error: savetype: undefined var
Reichibi.dmb - 2 errors, 0 warnings
In response to AngelReincarnation
var++ is pretty much shorthand for "increase var by 1".

text2path() is something you could easily look up in the reference. I saw that you had 'savetype' as a var that might contain "/turf/build/Roof1", which is text that could be converted directly to a type/path.
In response to Kaiochao
Oh so basically I did what I did with the other code but exclude the new.
Incidentally, you can actually use text directly in new() instead of a type path. text2path() isn't strictly necessary for that case, as internally it will do the same thing for you. I still think using text2path() is a good idea, though.