ID:261527
 
I can't get my NPCs to have different messages to say when clicked on. I don't understand why it's not working, here's the code.

mob
NPCs
Mother
icon = 'NPCs.dmi'
icon_state = "Mom"
Click()
if(get_dist(src.loc, usr.loc) <= 1)
usr << "I can't beleive you're old enough to go out on your own already. OH MY BABY! PROMISE ME YOU WON'T GET HURT OKAY?"
else
usr << "What?"
var/walkspeed = 35
New()
..()
wander()
proc
wander()
walk_rand(src, walkspeed)

Mayor
icon = 'NPCs.dmi'
icon_state = "Mayor"
Click()
if(get_dist(src.loc, usr.loc) <= 1)
usr << "Hello [usr]. Welcome to my home."
else
usr << "What?!"
walkspeed = 35
New()
..()
wander()
When you click on Mother or the Mayor, they both say the same thing, which is "Hello [usr]. Welcome to my home." I don't understand why it's doing that. Can somone please help?
You need to indent the second Click() and all that goes with it once to the right.
In response to Nadrew
Yep, Nadrew is right. By having the Click() proc at the same level as the Mother() proc, it is treated as a separate 'parent' proc - not a child of each object... You might even want to separate it completely, and have logic within that handles all the conversations, for example:
Click()
  if mother is nearby then
    "oh my baby..."
  else if mayor is nearby then
    "welcome to my home..."
  else
    "what?"

something along those lines, anyway. A good reason for a single proc to handle these events is that you have one place to make changes, instead of having the chance that you must go through all the Click() procs in your code to make changes... also helps to narrow possible bugs...
In response to digitalmouse
The only problem you might run into that way is if you have 50 or so NPC's, each one has their own entry. Not to mention, you'll have very inefficient code after about 10 - 13. ( I checked it )

I would use it if you're going to have less than 10 - 13 NPC's, but a more effective way is with Overloading.

Do something such as:

Click()
DoNPCTalk(usr,src)

Then just overload that with each NPC, like:

mob/npc/mayor
...lalalalala other code here....
DoNPCTalk(usr,src)
his say stuff....
....lalalalala more code....

That's what i do, and that way, you only have 1 proc, you can edit it wherever you want AND you are memory efficient and fast :-)
In response to ShadowWolf
ShadowWolf wrote:
I would use it if you're going to have less than 10 - 13
NPC's, but a more effective way is with Overloading.

Good point! Gee you're so smart! :) (actually I've been approaching DM from a too simple point of view - I forget it is a fairly robust OO Language...)