ID:266448
 
I am using the following code to allow a person access to an area and to move a guard north.
.....
Click()
var/area/invite_only/A
for(var/atom/T in locate(33,20,2))
if(T.type == /area/invite_only) A = T
if(src.key in A.invites) goto NEXT
var/password = input(usr,"Give the password, and I'll let you through!","Clerk") as text
if(lowertext(password) != "butterfly")
alert(usr,"Wrong password!","Clerk")
return
A.invites.Add(src.key)
NEXT
for(var/NPC/N in locate(A.x,A.y,A.z))
step(N,NORTH)
sleep(20)
step(N,SOUTH)


It gives me the following rutime error:

runtime error: Cannot read null.invites
proc name: Click (/NPC/Clerk/Arena/CompetetorOnly/Click)
usr: Lord of Water (/Player)
src: (/NPC/Clerk/Arena/CompetetorOnly)
call stack:
(/NPC/Clerk/Arena/CompetetorOnly): Click( (2,3,1) (/turf/City/Ground/StoneFloor))


Now, it would seem to me that I should be accessing an area and not a turf, even! Does anyone know what I am doing wrong?
Lord of Water wrote:
var/area/invite_only/A
for(var/atom/T in locate(33,20,2))
if(T.type == /area/invite_only) A = T

Now, it would seem to me that I should be accessing an area and not a turf, even! Does anyone know what I am doing wrong?

locate(33,20,2) returns a turf. You are telling it to look through the turf's contents for an area, but turfs can not contain areas. Areas contain turfs. turf.loc is the area that the turf is in. It is finishing the loop with no value for A, so you get the null.variable error.

try this:
var/area/invite_only/A
var/turf/T = locate(33,20,2))
A = T.loc
if(!istype(A))
// A is not an area/invite_only
else
// go ahead and do your stuff to A

In response to Shadowdarke
Hey, it worked! Thanks... I really need to get all of this stuff straight, though. I'll go look for a FAQ entry.