ID:2513397
 
(See the best response by Nadrew.)
Code:
turf
var/descriptor = "notset"
var/turfname = "notset"
Debug
icon = 'turf_debug.dmi'
Grass
icon_state = "grass"
turfname = "grass"
descriptor = "It is green and healthy. Its length barely reaches your ankles and is soft to the touch."
TallGrass
icon_state = "tallgrass"
turfname = "tall grass"
descriptor = "It is green and healthy. Its length reaches your chest and is very difficult to see through."

mob
verb
Search_Environment()
var T = new usr.loc
usr << "The floor beneath your feet is [T.turfname]. [T.descriptor]"


Problem description:
I am attempting to reference two vars that are used in /turf by grabbing usr.loc and referencing that turf inside /mob/verb. The vars fail as undefined since I don't fully understand how types work, it seems.
TextRPG.dme:17:error: T.turfname: undefined var
TextRPG.dme:17:error: T.descriptor: undefined var
2mobs.dm:26:warning: T: variable defined but not used

Edit: To clarify, I know I can fix this by placing the verb in /turf, but I want to access these variables as the player moves around as well. I'll inevitably have to reference these during /mob activity, right?
Best response
You don't need the 'new' keyword here, and you'll want to typecast the variable.

var/turf/T = usr.loc
usr << "The floor you're on is [T.type]"
Solved. I had actually thought just after I'd edited this, to remove "new" from the var. I'm not so sure why declaring /var/turf/T in stead of /var/T seems to behave differently. Shouldn't both methods automatically become type /turf/.. when I call usr.loc?
In response to YourLittleYuna
loc is not defined as a turf, it's defined as any atom, because movable atoms can be inside other movable atoms or areas too.

I'm not sure why you don't want this verb to just be defined on turf instead of mob. That way, usr would actually be necessary, and src is the turf involved with implicit access to its own variables.
BYOND is not a strictly typed language, any variable can be any type of value at runtime. Casting the variable as a /turf simply allows the compiler to know what variables and functions are avaliable to that object at compile-time.

At runtime those checks don't exist, if you set a typed turf variable to an /obj for instance, nothing will stop you, but you'll get a runtime error if you try to access a variable that doesn't exist on that object.