ID:272886
 
So I got this delete code.It works,deleting stuff just fine.But it lets anyone delete it. I'm not sure how to direct it, so that only the person who creates such an object can delete it.

mob
verb
Delete(obj/O in view())
if(usr.key)del(O)
else src<<"It's not yours."


Any help here?


-The Grimster
From what it looks like you're only checking if the person using the verb has a key which would let anyone delete it..What would work however is:
obj
var
owner // make this equal the owner of the object

mob
verb
Delete(obj/O in view())
if(O.owner == usr.key) // check if the var matches the key
del(O)
else
usr << "It's not yours"
In response to Mecha Destroyer JD
Um,you're pretty bad at indenting XD.But thanks!I didn't know that's what I was doing.

-The Grimster
In response to Mecha Destroyer JD
Oh wait, this code is bugged.It doesn't know who made the object =0.
In response to Gr1m d4 r34p3r
Gr1m d4 r34p3r wrote:
Um,you're pretty bad at indenting XD.But thanks!I didn't know that's what I was doing.

-The Grimster

Whatcha mean? On my screen his indents were perfect. If you were to copy/paste them though they'd look out of whack.
In response to ChicoTheMan94
Yeah I kinda did =P.So I just retyped them.
In response to Gr1m d4 r34p3r
No, his example required SOME thinking.

mob/verb/Create(obj/o)
o = new
o.owner=usr
In response to Gr1m d4 r34p3r
Gr1m d4 r34p3r wrote:
I didn't know that's what I was doing.
That pretty much sums it up.
You can't honestly expect to cut and paste an example someone's given and have it work immediately without figuring out how to use it, can you?
You introduce an "owner" variable to the object to check for and don't expect to have to do anything else than declare it? Did you think the variable was just going to read your mind on what to be assigned to?
Read the BYOND guide and understand it completely, use some common sense (I hear it's cheap on EBay these days), or give up entirely.

Oh, and the phrase is "Racking one's brain" though in your case "wrecking" certainly seems reasonable.