ID:1554136
 
(See the best response by Ter13.)
Code:
Dial
var/npct = "" //What the NPC will say
var/responses = list() // The available player responses

Resp
var/respt // What the response will say
var/Dial/next // Which Dialogue text the response will lead to.

mob
var
mob/talktarget // Who am I talking to?
Dial/activeDial // Which Dialogue message am I reading? (To prevent cheating with the "Topic")

proc
ShowDial() // This makes the Dialogue window pop up
winshow(src,"dial",1)

GetDial(mob/M,Dial/D) // Change what's showing in your dialogue window.
src.talktarget = M
src.activeDial = D // Remember which Dial is active so we can verify that a selected response is valid

if(D)
src << browse("<body bgcolor=black><font color=white><h3>[M.name]</h3><p>[D.npct]</p></font></body>", "window=dial")

var/i=1 //For our grid. This number changes per Resp.
for(var/Resp/R in D.responses) //We have Dial, now what datums are in the responses list?
src<<output("<a href='?src=\ref[src];action=respond;response=\ref[R]'>[R.respt]</a>","playerchoice:1,[i++]")

winset(src, "playerchoice", {"cells="1x[i-1]"})

mob
Topic(href,href_list[])
switch(href_list["action"])
if("respond") // If the link had its action set to "respond"
var/respId = href_list["response"] // Get the /Resp object's ID from the link's "response" param
var/Resp/R = locate(respId) // Use locate() to get the object based on the ID
if(istype(R) && activeDial && (R in activeDial.responses)) // Verify that this is a valid object, and not an old/spoofed link
GetDial(src.talktarget,R.next)


and the example

Dial/Old_Man

Greet
npct = "Greetings, traveller! How are you?"
responses = list(/Resp/Old_Man/Happy, /Resp/Old_Man/Mad)
Happy
npct = "Well, I'm glad to hear that! I'll be on my way!"
Mad
npct = "Oh, I'm sorry to hear that! I'll leave you alone!"

Resp/Old_Man

Happy
respt = "I'm doing great!"
next = /Dial/Old_Man/Happy
Mad
respt = "To be honest, I'm not doing too well, today. :("
next = /Dial/Old_Man/Mad

mob
Old_Man
icon = 'OldMan.dmi'
verb/talk()
set src in oview(1)
ShowDial()
GetDial(src, /Dial/Old_Man/Greet)


Problem description: I copyed and pasted these examples and system from the tutorials and snippets to try it out and it didnt function right

Error:

runtime error: bad client
proc name: ShowDial (/mob/proc/ShowDial)
usr: Guest-320239361 (/mob)
src: Old Man (/mob/Old_Man)
call stack:
Old Man (/mob/Old_Man): ShowDial()
Old Man (/mob/Old_Man): talk()
runtime error: Cannot read /Dial/Old_Man/Greet (/Dial/Old_Man/Greet).npct
proc name: GetDial (/mob/proc/GetDial)
usr: Guest-320239361 (/mob)
src: Old Man (/mob/Old_Man)
call stack:
Old Man (/mob/Old_Man): GetDial(Old Man (/mob/Old_Man), /Dial/Old_Man/Greet (/Dial/Old_Man/Greet))
Old Man (/mob/Old_Man): talk()


That's because in the talk() verb, src is equal to the NPC, not the player who used the verb.

usr would be what you would want to use.

I would also strongly question GamerMania's logic of using an object type per dialogue response, rather than using a initializer, or for that matter, a simple array of strings.
still


runtime error: bad client
proc name: ShowDial (/mob/proc/ShowDial)
usr: Guest-320239361 (/mob)
src: Old Man (/mob/Old_Man)
call stack:
Old Man (/mob/Old_Man): ShowDial()
Old Man (/mob/Old_Man): talk()
runtime error: Cannot read /Dial/Old_Man/Greet (/Dial/Old_Man/Greet).npct
proc name: GetDial (/mob/proc/GetDial)
usr: Guest-320239361 (/mob)
src: Old Man (/mob/Old_Man)
call stack:
Old Man (/mob/Old_Man): GetDial(Guest-320239361 (/mob), /Dial/Old_Man/Greet (/Dial/Old_Man/Greet))
Old Man (/mob/Old_Man): talk()
Best response
Yeah, this is a really, really bad example of code. There's a mess of confused ideas going on in GamerMania's example... Let me see if I can fix this...

        GetDial(mob/M,Dial/D) // Change what's showing in your dialogue window.
src.talktarget = M
src.activeDial = D // Remember which Dial is active so we can verify that a selected response is valid

if(D)
M << browse("<body bgcolor=black><font color=white><h3>[M.name]</h3><p>[D.npct]</p></font></body>", "window=dial")

var/i=1 //For our grid. This number changes per Resp.
for(var/Resp/R in D.responses) //We have Dial, now what datums are in the responses list?
M<<output("<a href='?src=\ref[src];action=respond;response=\ref[R]'>[R.respt]</a>","playerchoice:1,[i++]")

winset(M, "playerchoice", {"cells="1x[i-1]"})