ID:2131573
 
Resolved
There is now a built-in ref() proc. This acts as syntactic sugar for "\ref[object]".
Applies to:DM Language
Status: Resolved (513.1490)

This issue has been resolved.
it'd be neat if it was possible to get the \ref (or tag) value of an object or path or any sort of data using a function, so it doesn't need to be an embedded text or anything.

ref() maybe

I like this. It's on my list of possibilities for 512.
Can we treat this as a number or does it HAVE to be a string?
I think it would need to be a string because \ref will return the tag of an object, shouldn't it?
Can we make that optional? If I want to know something's tag, I'll just check the tag. If I want to know something's datatype/instance ID, I'll call ref().
In response to Ter13
Ter13 wrote:
Can we treat this as a number or does it HAVE to be a string?

I think it has to be a string because of precision issues.

Technically even the \ref macro's four-byte format is imprecise, since it cuts off an entire byte from the value to squeeze the type into the MSB. But with floating point numbers you end up with only three bytes of precision.

I would quite like to ditch the tag behavior that \ref has currently anyway, though, because sometimes tags are a problem (as I found out in an SS13 report recently). Doing so in an explicit function call makes even more sense.
hello friend
while your making this a function, the ability to get the two pieces of info directly would also be nice.

typeid() and instanceid()

or at the very least, typeid(). /tg/ has came in to a few cases where knowing that has been useful, and it would be nice to ditch the string parsing code we have to use
I decided not to add a proc, but I changed the \ref macro behavior which I think is more important for a lot of projects.
I'd still really like ref() as a function just to avoid having to do string stuff.
In response to Super Saiyan X
#define ref(x) "\ref[x]"


or, if you want X.ref():
/datum/proc/ref()
return "\ref[src]"


All a language-level `ref()` proc is going to do is give you the same string you'd get from `"\ref[x]"` anyway.
In response to GinjaNinja32
GinjaNinja32 wrote:
> #define ref(x) "\ref[x]"
>


or, if you want X.ref():
> /datum/proc/ref()
> return "\ref[src]"
>


All a language-level `ref()` proc is going to do is give you the same string you'd get from `"\ref[x]"` anyway.

sometimes i like to not touch the string table
In response to Super Saiyan X
That's moot; a ref() proc would add a new string to the table regardless.
In response to MrStonedOne
MrStonedOne wrote:
while your making this a function, the ability to get the two pieces of info directly would also be nice.

typeid() and instanceid()

or at the very least, typeid(). /tg/ has came in to a few cases where knowing that has been useful, and it would be nice to ditch the string parsing code we have to use

Lummox JR resolved issue with message:
There is now a built-in ref() proc. This acts as syntactic sugar for "\ref[object]".