ID:1170371
 
(See the best response by Kaiochao.)
Code:
mob/var/list/darkness = newlist(/obj/black,/obj/black2,/obj/black3,/obj/black4,/obj/blackTR,/obj/blackTL,/obj/blackBR,/obj/blackBL,/obj/blacktop,/obj/blackbottom,/obj/blackright,/obj/blackleft)

bed
icon = 'Icon Sheet 1.dmi'
icon_state= "bed"

verb

Sleep()

set src in oview(1)
usr.sleep = input("Would you like to go to sleep?") in list ("Yes","No")
if(usr.sleep == "Yes")
usr << "You fall asleep and enter the Dream World."
usr << sound(null)
usr << sound('calmtheme.ogg')
usr.client.screen += darkness
usr.Move(locate(6,6,2))

mob/verb

Wake_Up()

if(usr.sleep == "Yes")
usr.Move(locate(1,8,1))
usr.sleep = "No"
usr.client.screen -= darkness
else
usr << "You are already awake!"


Problem description: I have defined a list (of objects) under mob/var, and I am trying to call the same list in a verb under /obj/bed.

Included between the (dm) above I included a Wake_Up() verb under /mob that calls the list, and gives no errors.

When compiling, the error given is "error: darkness: undefined var" on the line under the Sleep() verb.

Why does it have a problem with the list when it is called under an obj verb but not under a mob verb.

Can someone please explain this?

Thanks again,

Balt

Best response
Variables defined under a certain type are only accessible to that type and types that inherit from it. Since 'darkness' is defined under /mob, /obj can't see it. If you have a reference to a mob, though (like usr), then you can access it through that mob. e.g. usr.darkness. Or, you could define 'darkness' as a global list variable.
Thanks. I used usr.darkness for when i need it under obj. Before i started this thread, i tried to define a different list with the same objects under obj/vars but i got a bunch of errors.


Anyway, i got it to work thanks to you.


Thanks again,

Balt