ID:1598474
 
(See the best response by Cloud Magic.)
Problem description:
Hello everybody, I am working on a little something involving lists and paths when I suddenly ran into a issue: when I use a verb to pick from a list, it'll return in the form of a path, not a name.

Now I know this has been extensively asked before and people gave answers such as using a Associative list like so:

obj
Apple
Orange

var/list/Fruits = list("Apple" = /obj/Apple, "Orange" = /obj/Orange)

mob/verb
All_Fruits(anything in Fruits)


But using this method just wont cut it out for me, since it would be a pain to do this for every single equipment I have.

So I asked for some help in Skype and a friend of mine told me I could return the name of said path with something like:

proc

path2name(path)
path = "[path]"
var pos, lastPos
do
lastPos = pos
pos = findtextEx(path, "/", pos + 1)
while(pos)
return copytext(path, lastPos + 1)


This indeed returns the name of said path. But there's a catch. It doesn't link the name to the path.

I want to be able to actually link the name to a specific path, like how Associative lists do. How can I go upon doing this?

What I have right now only returns the name, which is pretty useless..


Best response
When you get the path of an object you should be able to assign it to a reference and then print the name.

/obj/crayon

atom/movable/var/name

var/atom/movable/a = /obj/crayon//your path you got here

world << a.name
Wow... and here I was over complicating this so much. Thank you very much sir!