ID:157980
 
Basically, I want to be able to edit a turfs contents that a mob is standing on (so I can delete stacking objects for a build code).

In response to Jp
Thanks for the quick response.
Also, how do you search the contents to find if that type of object is already created? My current code is;

obj/build/Click()
if(!togglebuild)
for(var/obj/build/X in usr.contents)
X.togglebuild=0
usr << "You have selected [src]"
togglebuild=1

while(togglebuild)
var/obj/O = new()
var/turf/C = usr.loc
O.icon = src.icon
if(C.contents.Find(O))
return
O.loc = locate(usr.x, usr.y, usr.z)
O.density = src.density
sleep(1)
else
usr << "You have deselected [src]"
togglebuild=0
In response to Strong123488
I'm not following precisely what you're trying to do here, but I suspect you'd benefit from the locate() procedure. For example:

for(var/obj/build/X in usr.contents)
X.togglebuild=0


is better written as:

X.togglebuild = !(locate(/obj/build) in usr.contents)


locate reference: http://www.byond.com/docs/ref/info.html#/proc/locate

Are you looking specifically for any subclass of /obj/build, or one that matches src.type?
In response to Jp
obj/build/Click()
if(!togglebuild)
for(var/obj/build/X in usr.contents)
X.togglebuild=0
usr << "You have selected [src]"
togglebuild=1

while(togglebuild)
var/obj/O = new()
var/turf/C = usr.loc
O.name = src.name
O.icon = src.icon
for(var/obj/B in C.contents)
if(B.type == /obj)
del(B)
O.loc = locate(usr.x, usr.y, usr.z)
O.density = src.density
sleep(1)
else
usr << "You have deselected [src]"
togglebuild=0


Basically, I am trying to prevent more than 1 turf-like object being on that turf at once. Without doing this, it will just continue placing objects down even when I'm standing still and that is unessessary. The if(B.type==/obj) code works, but it will become broken when I add items, and they are lying on the floor.
In response to Strong123488
I see.

Assuming all of your 'turflike' objects are of type /obj/build:

mob
var
buildtype = null

Move()
.=..()
if(. && buildtype) if(!(locate(/obj/build) in loc)) Build()

proc/Build()
if(!buildtype) return
var/obj/o = new buildtype(loc)
o.name = name
o.icon = icon
o.density = density

obj/build/Click()
if(usr.buildtype)
usr.buildtype = null
else
usr.buildtype = type
if(!(locate(/obj/build) in loc)) usr.Build()


Completely untested. Will post explanation/fix bugs after dinner.

EDIT: Okay, thought about this slightly more, and you seem to have a player's-mob-passes-attributes-onto-construction paradigm for this thing that I'll attempt to emulate. Assume all 'turflike' objects are of type /obj/build:

mob
var
buildtype //We'll store the type of the object we're building in a mob variable

Move()
.=..() //Do the default Move() behaviour, and put the succeed/didn't succeed result into the variable '.'.

if(.) //If we successfully moved...
Build() //Then do some building

proc/Build()
if(!buildtype) return //If we're not building anything, just return

if(istype(buildtype, /obj/build)) if(locate(/obj/build) in loc) return //If we're building a 'turflike' object and there's one in our square already, don't bother

new buildtype(loc, src)

obj
build
New(loc, mob/m)
.=..(loc) //Make a new object, put it on 'loc'

icon = m.icon
density = m.density //Set built object attributes
name = m.name

Click()
if(usr.buildtype) //If we're already building something
usr.buildtype = null //Cancel it.
else
usr.buildtype = type //Otherwise, set the buildtype and build on the turf
usr.Build()


The advantage of this approach is that you don't have that infinite loop spinning all the time. And it should work for 'item-like' build objects when you throw those in.

Note that I'm not an expert on the building-game genre, and don't know quite how this is all supposed to work - this is mostly supposition based on your responses and the code you've shown.