ID:169765
 
Is there any way to get the value of a variable based on the typepath of the containing datum?
Sgeo wrote:
Is there any way to get the value of a variable based on the typepath of the containing datum?

Unfortunately no. A new form of initial() which took two arguments (a path and a var name) would be incredibly useful, but does not exist.

Lummox JR
Short and direct answer, no, as Lummox said. However, the answer is technically yes, since there is a way.
var/list/initial_variables[0]
proc/setup_initial_variables()
var
datum/D
list/L
for(var/type in typesof(/datum))
D = new type;L=new
for(var/V in D.vars)
L[V]=D.vars[V]
initial_variables[D.type]=L
del(D)

world/New()
setup_initial_variables()

proc/initial_from_type(type, variable)
var/list/L=initial_variables[type]
if(!(variable in L))return 0
return L[variable]

Just use the initial_from_type function, passing in a type path and a variable name.
client/verb/test(type_path in typesof(/datum),variable as text)
src<<initial_from_type(type_path, variable)