ID:752800
 
Keywords: access, datum, variable
(See the best response by Stephen001.)
Code:
datum
var/a = 1
var/b

New(c)
b = c
..()

// elsewhere
var/datum/d = new(datum.a)


Problem description:
Basically I'm trying to access variable a from datum. I tried datum.a which gives an undefined error. I also tried /datum.a and /datum/a but they don't work either.

var/datum/d = new(a)


Or if you want to pass another datum's variable into this datum's constructor.

var/datum2/d2 = new
var/datum/d = new(d2.a)

Best response
Essentially, what you need is an instance (an actual living version) of the datum you want to access.

I guess your logic is it should work a bit like world.tick_lag or similar variables, but when you do world.tick_lag, you can basically think of it like there's the following variable, internal to BYOND:

var/world/world = new()


And so, world.tick_lag is referring to that global variable, not the "world" datum by itself. Datums you make do not have that global variable, so you'd have to make:

var/datum/datum = new()


Somewhere in your code, to add a new global variable. Then:

var/datum/d = new(datum.a)


Will work, as the "datum" global variable is defined.

As a matter of curiosity, could you share a more specific example of what you're trying to do with datums? It helps, as they are very general, so it might be that I can make an even better recommendation than the one I just made!