ID:1685826
 
(See the best response by Super Saiyan X.)
If you have a verb that creates a house(obj), but checks if said obj already exists on the map how do you delete it? I want the player to be able to delete the old house by building a new one if they want to. I use the tag of the house to locate it, but I can't fucking delete it. I tried everything, I tried using locate;
del(locate("[src] house"))

tried adding the obj to a list on creation then deleting whats in the list. I tried using for;
for(var/obj/House/t in world)
if(t.tag == "[src] house")
del(t)

or making it a variable
var/obj/t = locate("[src] house")
del(t)

but nothing works. I'm sure I can delete it because I have a regular delete verb that works on the house. how the hell do i delete it
Are you sure you're actually finding one? It's possible your delete statements are never being reached.

locate("[src] house")

won't work because locate doesn't work with strings.

if(t.tag == "[src] house")

Are you sure there's an object that exists with that tag?

var/obj/t = locate("[src] house")
del(t)

Again that's not how locate works.
In response to Alex Peterson
Alex Peterson wrote:
Are you sure you're actually finding one? It's possible your delete statements are never being reached.

locate("[src] house")

won't work because locate doesn't work with strings.

if(t.tag == "[src] house")

Are you sure there's an object that exists with that tag?

var/obj/t = locate("[src] house")
> del(t)

Again that's not how locate works.

Actually, that's exactly how locate works.
In response to Super Saiyan X
You're kind of right SSX. That's assuming that what he's written is a tag. I don't usually do anything involving tags so my bad.

But yeah, nothing has that tag anyway. That's the only reason it wouldn't work.
    verb
Build_House()
set category = "Miscellaneous"
if(locate(/obj/House) in oview(0))
src << "You cannot build your home here."
return
if(locate("[src.ckey]'s House") in world)
input(src, "Do you want to delete your old house to make one here?") in list("No", "Yes")
if("No") return
if("Yes") return




src.map = SwapMaps_Find("[src.ckey]-house")

if(src.map)
src.Savedx = src.x
src.Savedy = src.y
src.Savedz = src.z

var/obj/House/Po = new/obj/House(src.loc)
Po.owner = src
Po.tag = "[src.ckey]'s House"
Po.name = "[src]'s House"
src.loc = locate(src.map.x1+12,src.map.y1+1,src.map.z1)
src.location = "[src]'s House"

else
src.Savedx = src.x
src.Savedy = src.y
src.Savedz = src.z

var/obj/House/Po = new/obj/House(src.loc)
Po.owner = src
Po.tag = "[src.ckey]'s House"
Po.name = "[src]'s House"

src.map = SwapMaps_CreateFromTemplate("zSmallHouse")
src.map.id = "[src.ckey]-house"
SwapMaps_Save(map)

src.loc = locate(src.map.x1+12,src.map.y1+1,src.map.z1)
src.location = "[src]'s House"



Where it says "if("Yes")" is where i put the code, it don't work
You're trying to locate "[src] house", but the code right there says that the tag is being assigned as, "[src.ckey]'s House" - you'd have to locate that statement, or change your tags to "[src] house".
Just gonna take a stab in the dark. You know "[src.ckey] house" != "[src] house" right? ckey is a shortened version of the person's key.
I just had changed it recently because I realized anyone with the same name could delete someone else's house. Previously I had them matching up.
In response to Gluscap
Not entirely sure what you're saying but

del(locate("[src] house"))


Won't work because it's

del(locate("[src.ckey]'s House"))
Alex, he is saying his tags and locates matched up before, but just changed them.


Gluscap. Can you show the entire procedure where you are trying to locate and delete the house?
The tag used to be "[src] house", the player has a name they choose and the same name can be used over and over. For example two players could be named "Gluscap", so both player's houses would be named "Gluscap house" and when they delete their house using the code it could delete the other's house. While waiting for a reply I was trying to fix up my code.

    verb
Build_House()
set category = "Miscellaneous"
if(locate(/obj/House) in oview(0))
src << "You cannot build your home here."
return
if(locate("[src.ckey]'s House") in world)
input(src, "Do you want to delete your old house to make one here?") in list("No", "Yes")
if("No") return
if("Yes")
del(locate("[src.ckey]'s House"))
goto makehouse

makehouse
src.map = SwapMaps_Find("[src.ckey]-house")

if(src.map)
src.Savedx = src.x
src.Savedy = src.y
src.Savedz = src.z

var/obj/House/Po = new/obj/House(src.loc)
Po.owner = src
Po.tag = "[src.ckey]'s House"
Po.name = "[src]'s House"
src.loc = locate(src.map.x1+12,src.map.y1+1,src.map.z1)
src.location = "[src]'s House"

else
src.Savedx = src.x
src.Savedy = src.y
src.Savedz = src.z

var/obj/House/Po = new/obj/House(src.loc)
Po.owner = src
Po.tag = "[src.ckey]'s House"
Po.name = "[src]'s House"

src.map = SwapMaps_CreateFromTemplate("zSmallHouse")
src.map.id = "[src.ckey]-house"
SwapMaps_Save(map)

src.loc = locate(src.map.x1+12,src.map.y1+1,src.map.z1)
src.location = "[src]'s House"
Before I say anything. Goto... Oh god.
After I click "Yes" it doesn't execute the rest of the code, so I thought that a goto was needed to continue the proc(even though it usually isn't needed if it isnt returned after the if statement). Doesn't work tho, so I guess it was unneeded.
In response to Gluscap
Exactly, you should never need goto. So what you're saying is that del() never finishes. It gets stuck. That's why it never continues.

Sounds like an infinite loop.
Have you edited the house object's Del() proc? That would explain it.
Nope, I did use bumped though.

obj
House
icon = 'Icons/Turfs 3.dmi'
icon_state = "house"
var/mob/owner
density = 1
Bumped(var/mob/M in players)
M.Savedx = src.x
M.Savedy = src.y-1
M.Savedz = src.z
var/swapmap/SM = SwapMaps_Load("[owner.ckey]-house")
M.loc = locate(SM.x1+12,SM.y1+1,SM.z1)
M.location = "[owner]'s House"
Best response
Your issue isn't the locate, it's in the input(). That literally does nothing. The input returns the value of the option selected, which then needs to be compared.

you could try something like:
var/house = locate("[src.ckey]'s House")
if(house && \
alert("Do you want to delete your old house to make one here?","delete house","No", "Yes")=="Yes")
del(house)


or, for the more readable version you'd probably like to use:
var/house = locate("[src.ckey]'s House")
if(house)
var/delete = input(src, "Do you want to delete your old house to make one here?") in list("No", "Yes")
if(delete == "Yes") del(house)
Or...
        var/input = input(src, "Do you want to delete your old house to make one here?") in list("No", "Yes")
if(input == "No")
if(input == "Yes")
Thank you. i don't use locate often so i thought it was that, wasted so much time trying to make up ways to delete the object when the first one wasn't wrong in the first palce.
just an fyi, I fixed the indentation in my snippet. I don't know how I messed that up.