There are 3 basic parts of this code you have to understand.
1. The first step is to make a command that will call the process, in my example I used an apostrophe as the speak command, it's common and quick for me.
Example: 'hello world! - I think I'm Dead exclaims, "Hello world!"
command <'#text#> do <speaker>
Now that you have the command you need what it calls, the procedure.
2. Paste this procedure into your text file around any other procedures you have(generally near the bottom of your file...ie: not in the game definition block).
define procedure <speaker>
set numeric <said; 0>
set numeric <q; 0>
set numeric <s; 0>
set numeric <e; 0>
set numeric <a; 0>
set numeric <wordsearch; 0>
set numeric <searchresults; 0>
set numeric <detectedqkeys; 0>
set numeric <detectedekeys; 0>
set numeric <detectedskeys; 0>
set numeric <detectedakeys; 0>
for each object in <#quest.currentroom#> if property <#quest.thing#; npc> then {
set numeric <searchresults; %searchresults% + 1>
set numeric <say-length-format; $lengthof(#quest.command#)$ - 1>
set string <text; $right(#quest.command#; %say-length-format%)$>
set string <punctuation-format; $right(#quest.command#;1)$>
set string <searchname; $displayname(#quest.thing#)$>
for each object in <#quest.currentroom#> if ( $objectproperty(#quest.thing#; speaking)$ = yes ) then {
if ( #punctuation-format# = ? ) then {
msg <You ask, "$capfirst(#text#)$"|n>
set numeric <said; 1>
for <q; 1; $objectproperty(#quest.thing#; qkeywords)$> {
set string <qkeyword; $objectproperty(#quest.thing#; qkeyword%q%)$>
if ( $instr(#text#; #qkeyword#)$ <> 0 ) then {
set numeric <detectedqkeys; %detectedkeys% + 1>
set string <qanswer; $objectproperty(#quest.thing#; qanswer%q%)$>
msg <#qanswer#>
}
}
}
}
}
if ( #punctuation-format# = ! ) then {
msg <You exclaim, "$capfirst(#text#)$"|n>
set numeric <said; 1>
for <e; 1; $objectproperty(#quest.thing#; ekeywords)$> {
set string <ekeyword; $objectproperty(#quest.thing#; ekeyword%e%)$>
if ( $instr(#text#; #ekeyword#)$ <> 0 ) then {
set numeric <detectedekeys; %detectedekeys% + 1>
set string <eanswer; $objectproperty(#quest.thing#; eanswer%e%)$>
msg <#eanswer#>
}
}
if ( #punctuation-format# = . ) then {
msg <You say, "$capfirst(#text#)$"|n>
set numeric <said; 1>
for <s; 1; $objectproperty(#quest.thing#; skeywords)$> {
set string <skeyword; $objectproperty(#quest.thing#; skeyword%s%)$>
if ( $instr(#text#; #skeyword#)$ <> 0 ) then {
set numeric <detectedskeys; %detectedskeys% + 1>
set string <sanswer; $objectproperty(#quest.thing#; sanswer%s%)$>
msg <#sanswer#>
}
}
if ( #punctuation-format# <> ? ) and ( #punctuation-format# <> ! ) and ( #punctuation-format# <> . ) then {
msg <You say, "$capfirst(#text#)$"|n>
set numeric <said; 1>
for <a; 1; $objectproperty(#quest.thing#; akeywords)$> {
set string <akeyword; $objectproperty(#quest.thing#; akeyword%a%)$>
if ( $instr(#text#; #akeyword#)$ <> 0 ) then {
set numeric <detectedakeys; %detectedakeys% + 1>
set string <aanswer; $objectproperty(#quest.thing#; aanswer%a%)$>
msg <#aanswer#>
}
}
}
}
}
else {
set numeric <say-length-format; $lengthof(#quest.command#)$ - 1>
set string <text; $right(#quest.command#; %say-length-format%)$>
set string <punctuation-format; $right(#quest.command#;1)$>
set string <searchname; $displayname(#quest.thing#)$>
if ( #punctuation-format# = ? ) and ( %said% = 0 ) then msg <You ask, "$capfirst(#text#)$"|n>
if ( #punctuation-format# = ! ) and ( %said% = 0 ) then msg <You exclaim, "$capfirst(#text#)$"|n>
if ( #punctuation-format# = . ) and ( %said% = 0 ) then msg <You say, "$capfirst(#text#)$"|n>
if ( #punctuation-format# <> ? ) and ( #punctuation-format# <> ! ) and ( #punctuation-format# <> . ) and ( %said% = 0 ) then msg <You say, "$capfirst(#text#)$"|n>
}
end define
The procedure is now in place, now the most important part is how you use it.
3. USE - This procedures relies on objects that are listening to have a few properties, I'll explain the reason for them, their use and such as we go through.
First property an object will need to be given is one called 'npc'(without the apostrophes of course). This defines the object as a creature capable of speaking or interacting based on what is said around it. This property doesn't need a value, it's suggested you don't give it one.
Second property is one called 'speaking' this property does have a value option, basically boolean, yes or no. I included this check to easily implement having characters who ignore you and such until you've completed some task. In order for a npc to be 'listening' to what's being said around, the value of the speaking property must be 'yes'.
Now creating the final product. This procedure looks for properties called, qkeywords(question keywords, responds to questions, eg 'how are you?), skeywords(say keywords, responds to general statements, 'it's hot out.), ekeywords(exclaim keywords, responds to exclaimed statements, 'HELP!) and akeywords(anything keywords, used for text without an appropriate punctuation at the end).
These properties should have a value equaling the total amount of the type of keywords you have given the npc to listen for. qkeywords should be a count of only keywords heard in questions, skeywords statements, etc.
Next this procedure looks for the keywords for the type, these should be properties called 'qkeyword1, ekeyword3, etc. The value for each of these properties should be what word you want the npc to listen for from the players SAY command.
Hand in hand with the qkeyword1 type property, are answer properties. These should be called as such... qanswer1, sanswer5, etc. The value for this property should be exactly what you want messaged to the player when they say this word around the npc(if it is listening). If you want a person to sneeze, or say something in return, place the message here exactly how you want it displayed to the player. An example of how an npc object would look coded is as follows...
define object <obj1>
alias <puppy>
prefix <a scruffy, overgrown>
properties <npc; l=2, w=2; speaking=yes; ekeywords=0; skeywords=0; akeywords=0; qkeywords=5; qkeyword1=where; qkeyword2=you alright; qkeyword3=bite; qkeyword4=home; qkeyword5=come with; qanswer1=The young puppy playfully paws at your leg.; qanswer2=The puppy sneezes suddenly, a shocked expression fills it's face.; qanswer3=The puppy playfully growls at you and scuffles around a bit.; qanswer4=The puppy sniffs around the area, finding nothing in particular.; qanswer5=The puppy yawns and settles on the ground.>
end define
Now to see how this code works, you should try running your game with all these pieces of code added to it, and try to talk to the npc.
***NOTICE*** For this quick make up, I made it a requirement for you to say the npc's name in the sentence for it to listen for other keywords. It is easily changed, but I hastily threw it in there to make it close to what was being described, even though I know it's not very open ended. An example on how to use this npc would be to type.... 'are you alright puppy?
This will message...
You ask, "Are you alright puppy?"
And then some simple message I gave the puppy that responds to, 'you alright'.
It's easily changed to not require saying the name, but eh, like I said, I thought it went. Try it out, post on any problems and let me know of any troubles/bugs or your success.
' "Speaker Test"
define game <Speaker Test>
asl-version <350>
start <room>
game info <Testing Co-ordinate/Grid Based Ideas>
error <badcommand; I don't understand what you typed.>
error <badthing; I could not find what you were referring to.>
error <badplace; You can't go there.>
error <itemunwanted; Your offer has been declined.>
error <defaultuse; I don't understand what you typed.>
error <cantdrop; For some reason you can't drop that.>
error <noitem; I could not find what you were referring to.>
error <badexamine; What is it you would like to examine?>
error <badgo; You can't go there.>
error <baduse; I don't understand what you typed.>
error <badgive; Give to whom?>
error <badtake; You can't pick that up.>
error <baditem; I could not find what you were referring to.>
error <baddrop; You are not holding that.>
error <badpronoun; I could not find what you were referring to.>
error <defaultout; You can't go there.>
background <black>
foreground <white>
panes off
'specifies room appearance
description {
msg <[$objectproperty(#quest.currentroom#; title)$]>
if ( #quest.formatobjects# <> ) then msg <$objectproperty(#quest.currentroom#; look)$ You also see here #quest.formatobjects#.> else msg <$objectproperty(#quest.currentroom#; look)$>
if not <#quest.doorways.dirs#> then msg <Obvious exits: none> else msg <Obvious exits: #quest.doorways.dirs#>
}
command <'#text#> do <speaker>
end define
define room <room>
alias <The Grid>
properties <title=The Grid; look=Massive white lines cross vertically and horizonally over the surfaces of this room making it impossible to tell it's true size.>
define object <obj1>
alias <puppy>
prefix <a scruffy, overgrown>
properties <npc; speaking=yes; ekeywords=1; skeywords=0; akeywords=0; qkeywords=5; ekeyword1=die; eanswer1=The puppy is suddenly startled and begins whimpering.; qkeyword1=where; qkeyword2=you alright; qkeyword3=bite; qkeyword4=home; qkeyword5=come with; qanswer1=The young puppy playfully paws at your leg.; qanswer2=The puppy sneezes suddenly, a shocked expression fills it's face.; qanswer3=The puppy playfully growls at you and scuffles around a bit.; qanswer4=The puppy sniffs around the area, finding nothing in particular.; qanswer5=The puppy yawns and settles on the ground.>
end define
end define
define procedure <speaker>
set numeric <said; 0>
set numeric <q; 0>
set numeric <s; 0>
set numeric <e; 0>
set numeric <a; 0>
set numeric <wordsearch; 0>
set numeric <searchresults; 0>
set numeric <detectedqkeys; 0>
set numeric <detectedekeys; 0>
set numeric <detectedskeys; 0>
set numeric <detectedakeys; 0>
for each object in <#quest.currentroom#> if property <#quest.thing#; npc> then {
set numeric <searchresults; %searchresults% + 1>
set numeric <say-length-format; $lengthof(#quest.command#)$ - 1>
set string <text; $right(#quest.command#; %say-length-format%)$>
set string <punctuation-format; $right(#quest.command#;1)$>
set string <searchname; $displayname(#quest.thing#)$>
for each object in <#quest.currentroom#> if ( $objectproperty(#quest.thing#; speaking)$ = yes ) then {
if ( #punctuation-format# = ? ) then {
msg <You ask, "$capfirst(#text#)$"|n>
set numeric <said; 1>
for <q; 1; $objectproperty(#quest.thing#; qkeywords)$> {
set string <qkeyword; $objectproperty(#quest.thing#; qkeyword%q%)$>
if ( $instr(#text#; #qkeyword#)$ <> 0 ) then {
set numeric <detectedqkeys; %detectedkeys% + 1>
set string <qanswer; $objectproperty(#quest.thing#; qanswer%q%)$>
msg <#qanswer#>
}
}
}
}
}
if ( #punctuation-format# = ! ) then {
msg <You exclaim, "$capfirst(#text#)$"|n>
set numeric <said; 1>
for <e; 1; $objectproperty(#quest.thing#; ekeywords)$> {
set string <ekeyword; $objectproperty(#quest.thing#; ekeyword%e%)$>
if ( $instr(#text#; #ekeyword#)$ <> 0 ) then {
set numeric <detectedekeys; %detectedekeys% + 1>
set string <eanswer; $objectproperty(#quest.thing#; eanswer%e%)$>
msg <#eanswer#>
}
}
if ( #punctuation-format# = . ) then {
msg <You say, "$capfirst(#text#)$"|n>
set numeric <said; 1>
for <s; 1; $objectproperty(#quest.thing#; skeywords)$> {
set string <skeyword; $objectproperty(#quest.thing#; skeyword%s%)$>
if ( $instr(#text#; #skeyword#)$ <> 0 ) then {
set numeric <detectedskeys; %detectedskeys% + 1>
set string <sanswer; $objectproperty(#quest.thing#; sanswer%s%)$>
msg <#sanswer#>
}
}
if ( #punctuation-format# <> ? ) and ( #punctuation-format# <> ! ) and ( #punctuation-format# <> . ) then {
msg <You say, "$capfirst(#text#)$"|n>
set numeric <said; 1>
for <a; 1; $objectproperty(#quest.thing#; akeywords)$> {
set string <akeyword; $objectproperty(#quest.thing#; akeyword%a%)$>
if ( $instr(#text#; #akeyword#)$ <> 0 ) then {
set numeric <detectedakeys; %detectedakeys% + 1>
set string <aanswer; $objectproperty(#quest.thing#; aanswer%a%)$>
msg <#aanswer#>
}
}
}
}
}
else {
set numeric <say-length-format; $lengthof(#quest.command#)$ - 1>
set string <text; $right(#quest.command#; %say-length-format%)$>
set string <punctuation-format; $right(#quest.command#;1)$>
set string <searchname; $displayname(#quest.thing#)$>
if ( #punctuation-format# = ? ) and ( %said% = 0 ) then msg <You ask, "$capfirst(#text#)$"|n>
if ( #punctuation-format# = ! ) and ( %said% = 0 ) then msg <You exclaim, "$capfirst(#text#)$"|n>
if ( #punctuation-format# = . ) and ( %said% = 0 ) then msg <You say, "$capfirst(#text#)$"|n>
if ( #punctuation-format# <> ? ) and ( #punctuation-format# <> ! ) and ( #punctuation-format# <> . ) and ( %said% = 0 ) then msg <You say, "$capfirst(#text#)$"|n>
}
end define
command <ask #@person# about #@subject#> {
if action <#person#;ask> then doaction <#person#;ask> else {
if ( #(person):displaytype# = person ) then msg <You ask $displayname(#person#)$ about #subject#. But there is no response.> else msg <Why would you ask the $displayname(#person#)$ about #subject#? You need to get a hold of yourself.>
}
}action <ask> {
if ( #subject# = key ) then msg <"Ah yes, I put that key there yesterday. It was an extra that your father had.">
if ( #subject# = table ) then msg <"Yes, we have had that in my family for a long time. Isn't it elegant?">
if ( #subject# = book ) then msg <"Yes, I sure do love to read that book.">
}If ... then {
if ... then {
if ... then {
}
else {
default message
}
}
}Flag [default] (on)
If ... then {
[message]
flag off [default]
}
If ... then {
[message]
flag off [default]
}
if flag [default] then {
[default message]
}action <ask> {
if ( #subject# = key ) then msg <"Ah yes, I put that key there yesterday. It was an extra that your father had.">
if ( #subject# = table ) then msg <"Yes, we have had that in my family for a long time. Isn't it elegant?">
if ( #subject# = book ) then msg <"Yes, I sure do love to read that book.">
}If the subject is none of the above then msg <"I don't know anything about that.>
I don't want to see this thread fade too quickly. Al (MaDbRiT), are you making any progress on your conversation options in your library?