ID:146859
 
Can someone help me with these errors?
mob/verb/CreateDoor()
var/A=new/obj/Door(usr.loc)
A.password=input("What should the door's password be?")

obj/var/password
obj/var/Open
obj/var/Closed
obj/Door
verb
Open()
set src in view(1)
if(src.Open) return
var/Guess=input("What is the door's password?")
if(Guess==src.password)
src.Closed=0
src.Open=1
Close()
set src in view(1)
if(src.Closed) return
src.Closed=1
src.Open=0
The errors are
Here.dm:25:error:A.password:undefined var
Here.dm:24:A :warning: variable defined but not used

I made a mistake. It's var/obj/A
In response to Artekia
so where do i put that?
In response to Tsonic112
Replace var/A with var/obj/A
In response to Artekia
It worked!!Thank you man!
Ack. This door code is horrible. I know it's not yours, that you're just working from a bad example, so let me show you how to fix it.

mob/verb/CreateDoor()
var/A=new/obj/Door(usr.loc)
A.password=input("What should the door's password be?")


Let's start here. That var/A shouldn't be var/obj/A as Artekia said to try to fix it. It should have been var/obj/door/A all along, like so:
var/obj/door/A = new(usr.loc)


One of the first rules of DM: Always give a var whatever specific type you can.

I changed door to lowercase, because it's preferable to use lowercase var and path names. That's the standard convention. Now let's move on to the code below.

obj/var/password
obj/var/Open
obj/var/Closed


I'm not sure there's a point in making password a var common to all objs, but maybe there's a use for it. At any rate the bigger problem is those Open and Closed vars. They're capitalized, which as I mentioned is a bad idea, but that's not the real problem. The problem is that there are two vars doing the work of one, and you don't need either. If you had to have one, though, just keep one and ditch the other. Otherwise you set yourself up for the kind of bugs where Open and Closed could both be true, or both false. Since the door can't be both, a single var will suffice.

(Take a second look at Artekia's original code and consider what would happen if both vars were true. You'd have a door stuck either open or closed that you couldn't change. Under normal circumstances that isn't a problem, but weird things can and do happen. This kind of code is called brittle, because if another piece of brittle code interacts with it they can sometimes break pretty badly. The way to go is robust code, which can handle a few minor glitches.)

I did say that you don't need either of those vars, though. That's because for a door, all you need is the density var. If that's 1, the door is closed. If it's 0, the door is open. Therefore in the Open() verb you'd bail out if(!density) instead of if(Open), and in Close() you'd use if(density) in place of if(Closed).

Lummox JR