ID:148728
 
I've tabbed the following code down for readability. It's from my build command for Survival. My error is near the end, with the loop to delete objects, it will only delete a random amount of the item. Sometimes 2, sometimes 5, sometimes all 10. Does anyone know why this might be?

if("House")
var/typewall = input("What element?","Build","") in list("West to east","North to south","Floor")
var/amount = 0
for(var/obj/O in usr)
if(istype(O,/obj/wood))
amount += 1
if(amount >= 10)
var/turf_cert = 0
for(var/turf/T in view(0))
if(istype(T,/turf/grass_1))
turf_cert += 1
if(turf_cert >= 1)
usr.action = "building house wall"
usr.mess("You start building a house wall. (100)")
sleep(100)
if(prob(usr.skill_craft * 2))
usr.mess("You create a wall!")
var/T1
if(typewall == "West to east")
T1 = new /atom/structure/wood_wall_edge(usr.loc)
if(typewall == "North to south")
T1 = new /atom/structure/wood_wall_top(usr.loc)
if(typewall == "Floor")
T1 = new /atom/structure/wood_floor(usr.loc)
T1:owner = usr
else
usr.mess("You failed! The materials were ruined!")
if(prob(usr.skill_aptitude))
usr.skill_craft += 1
usr.mess("Your craft skill improved!")
var/amount_deleted = 0
usr.action = 0
for(var/obj/I in usr)
if(istype(I,/obj/wood))
if(amount_deleted <= 9)
amount_deleted += 1
usr << "Debug: deleted [I] (so far [amount_deleted])"
del(I)
usr.action = 0
del(src)
else
usr.mess("You need to have a clear plot of grass!")
else
usr.mess("You need to have at least 10 wood!")




~Polatrite~
Well, this method is somewhat inefficient. I don't know what your problem is, but I have another suggestion:

Create a temporary contents list, equal to the person's contents.
Delete 10 of the /obj/wood, incrementing each time.
Once 10 are deleted, do X
If 10 can't be deleted, display error message, and reset contents back to backup.

That way, you only need 1 for() loop. Also, for future reference, you can rewrite:

var/amount_deleted = 0
for(var/obj/I in usr)
if(istype(I,/obj/wood))
if(amount_deleted <= 9)
amount_deleted += 1

usr << "Debug: deleted [I] (so far [amount_deleted])"
del(I)

to:

for(var/i = 0, i < 9, i++)
var/obj/wood/W = locate() in usr
del(W)

which will delete 10 /obj/wood from usr. In fact, try doing that first.