Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sat Oct 23, 2010 5:34 pm   

Match Database Variable Key
 
Is there a way to match to a database key? I don't see a way to do it. I know you can match the database value, but I want to match the key.
Database Variable named: Words
Code:

have = hath
you = thou


Now how the heck do you match it.
#show %match("you", XXXXXXX)
I've don't see a way to reference the database variable key.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
complex
Apprentice


Joined: 12 Apr 2004
Posts: 134
Location: USA

PostPosted: Sat Oct 23, 2010 6:16 pm   
 
This command works for me.

#show %match(@drMobs,"A giant centipede is here.")

@drMods is the name of the data record variable that holds the desired information
"A giant centipede is here." is the first member of that list.

The above command returns 1, indicating it is the first member

The second member of that list is "A large crystal eagle swoops by."

so the command

#show %match(@drMobs,"A large crystal eagle swoops by.")

returns 2.

Is that what you were looking for?
_________________
<Clever text here>
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sat Oct 23, 2010 6:38 pm   
 
complex wrote:


#show %match(@drMobs,"A giant centipede is here.")

#show %match(@drMobs,"A large crystal eagle swoops by.")

It sounds like that isn't a database variable. You're example is a string list NOT a database variable. I even tried that and it matches the value NOT the key.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
complex
Apprentice


Joined: 12 Apr 2004
Posts: 134
Location: USA

PostPosted: Sat Oct 23, 2010 10:19 pm   
 
Weird, considering the type is Database record. Oh well sorry.
_________________
<Clever text here>
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sat Oct 23, 2010 11:12 pm   
 
I think I need to look at what I am doing a little differently. I am still working on a package the changes the speech of the character. I got a few done and now I am working on converting a sentence to Old English. But I think I need to look at it differently then the other ones I've changed and fixed.
Again here is an example sentence that will get converted:
Code:

say Your companion has come for you.


Here is my database variable:
Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <var name="OldEnglish" type="Record">
    <value>asked=besought|above=onuppan|a lot=overmany|you=thou|has=hath|had=hath|ask=beseech|are=art|from where=whence|to know=wit|to grow=wax|to give=bequeath|plentiful=fullsome|apprentice=proby|nothing=naught|to linger=tarry|yours=thine|horrible=pudh|do=dost|to where=whither|years ago=yore|friend=fere|from now on=henceforth|there=thither|your=thy|will=shalt|thou=ye|sell=syllan|rich=fullsome|pull=draught|none=nary|lake=mere|knew=wist|here=hither|have=hath|fork=pece|does=dost|dare=durst|I pray thee=prithee|to think=trow|coming=cometh|comes=cometh|you're=thou art|to become=wax|companion=fere|between=betwixt|request=beseech</value>
    <json>{"asked":"besought","above":"onuppan","a lot":"overmany","you":"thou","has":"hath","had":"hath","ask":"beseech","are":"art","from where":"whence","to know":"wit","to grow":"wax","to give":"bequeath","plentiful":"fullsome","apprentice":"proby","nothing":"naught","to linger":"tarry","yours":"thine","horrible":"pudh","do":"dost","to where":"whither","years ago":"yore","friend":"fere","from now on":"henceforth","there":"thither","your":"thy","will":"shalt","thou":"ye","sell":"syllan","rich":"fullsome","pull":"draught","none":"nary","lake":"mere","knew":"wist","here":"hither","have":"hath","fork":"pece","does":"dost","dare":"durst","I pray thee":"prithee","to think":"trow","coming":"cometh","comes":"cometh","you're":"thou art","to become":"wax","companion":"fere","between":"betwixt","request":"beseech"}</json>
  </var>
</cmud>


Now I want the script to convert the saying to:
Code:

say Thy fere hath cometh for thou.


I currently take the sentence and put it into a local sentence variable run it through a for loop.
Code:

$sentence = %replace( $sentence, " ", "|")
#forall $sentence {
// Need how to match here! Sometimes I need to match multiple words to convert to the old english one.
}

_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Sat Oct 23, 2010 11:18 pm   
 
To get this to work the way you'd like it to, I believe you'd need to loop through the record @word and construct a local variable with all of the keys combined in to a list. An easier method might be having two lists with items that match up, according to their positions in their respective lists.

ie.
Code:
NewEnglish = you|have
OldEnglish = thou|hath


Then you can do something like:
Code:
#IF %match("you", %concat("^({", @NewEnglish, "})"), $new_word) {
  $old_word = %item(@OldEnglish, %ismember($new_word, @NewEnglish))
  #SHOW Replace $new_word with $old_word
  }
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sat Oct 23, 2010 11:27 pm   
 
That totally doesn't make sense. First I don't have a global variable called word. Second you have the word "you" hardcoded in your if statement which I am NOT going to do. Third why would I have two separate variables
when I have a database variable which does that. The key is New English and the value is Old English.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Sat Oct 23, 2010 11:52 pm   
 
Calm thyself, grasshopper. I hoped you could take that snippet of code and adapt it appropriately to work within your alias. The instance of "you" was taken from your first post.

Since thinking about it a little more, I've realized there's a much simpler way to go about it.
Code:
$sentence = "Your companion has come for you."
#LOOPDB @OldEnglish {
  $sentence = %replace($sentence, %key, %val)
  }
#SAY $sentence


You'll have to adapt this at least a little, in order to convert capitalized words, and worry about words you are converting appearing within other words.
ie 'Your' doesn't get converted since %replace() is case sensitive and a word like 'dare' contains the characters 'are' which gets converted to 'art' making the word 'dart', which you don't want.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Oct 24, 2010 2:04 am   
 
Actually, there's an even simpler way to do it: %dbkeys(). This function returns a stringlist of all the keys in a datarecord. If it's a trigger pattern, you can also just use the stringlist pattern (I seem to recall it being the same thing, but I typically don't use it for anything but actual stringlists).)
_________________
EDIT: I didn't like my old signature
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Oct 24, 2010 2:16 am   
 
Matt. I tried the %dbkeys(), but that doesn't work. I might not be using it correctly though.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Oct 24, 2010 5:20 am   
 
Here's a rough copy of a script I just wrote for this situation:

Code:
#LOCAL NewString String
$NewString=%null
$String=%replace( %1, " ", " |")
#SAY $String
#FORALL $String {#IF (%iskey(@saychange,%trim( %i))) {$NewString=%concat( $NewString, %db( @SayChange, %trim(%i)), " ")} {$NewString=%concat( $NewString, %i)}}
#SAY $NewString


Hopefully, this will help you. I tested it on my side with an alias, and:

You have shaken your drink, sir.

returned

thou hath shaken thy drink, sir.

Charneus
Reply with quote
harley
Apprentice


Joined: 05 Apr 2008
Posts: 121

PostPosted: Sun Oct 24, 2010 9:03 pm   
 
Not sure this would be the way to go about it but what about
#loopdb?

ie
#loopdb @words {
#if (%1 = %key) {etc}}
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Oct 24, 2010 9:29 pm   
 
charneus wrote:
Here's a rough copy of a script I just wrote for this situation:

Code:
#LOCAL NewString String
$NewString=%null
$String=%replace( %1, " ", " |")
#SAY $String
#FORALL $String {#IF (%iskey(@saychange,%trim( %i))) {$NewString=%concat( $NewString, %db( @SayChange, %trim(%i)), " ")} {$NewString=%concat( $NewString, %i)}}
#SAY $NewString


Hopefully, this will help you. I tested it on my side with an alias, and:

You have shaken your drink, sir.

returned

thou hath shaken thy drink, sir.

Charneus

Thanks Charneus,
How would you handle it if the last word in the sentence had one of the words that need converted. I tried a few ways to detect the punctuation but I couldn't get it to work. Would appreciate the help.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Oct 24, 2010 9:33 pm   
 
Continuing onto this.... I did the change like Charneus suggested to get the Old English converstion to work and I noticed now when I do a stutter from the function sometimes the NewSentence doesn't display.
I can't figure this one out. I've put #print all over it to look at it and turned on the debug and the debug doesn't show up anything.
Here is the function:
Code:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <func name="SpeechType">
    <value><![CDATA[#local $matched $channel $input $person $sentence $emphasis $loopcount $word $NewSentence
//$NewSentence = %null
$channel = %1
$input = %params( 2)
#print $input
$loopcount = 0
;Check to see if the channel is a member of the sayto list
#if (%ismember( $channel, @sayto)) {
;Assign person variable and remove person from input variable
  $person = %concat( %word( $input, 1), " ")
  $input = %remove( $person, $input)
  }
#print After channel check: $input
;Check for a space a beginning of input and remove
$input = %trim( $input)
;Next check for an emphasis
#if (%begins( $input, "(")) {
  #call %match( $input, "(~(*~))(*)", $emphasis, $sentence) 
;Remove space at beginning of sentence to prepare to change into string list
  $sentence = %trim( $sentence)
  } {$sentence = $input}
#print Before sentence check: $sentence
;Change sentence into string list
$sentence = %replace( $sentence, " ", "|")
;Check which speech to do.
#forall $sentence {
  #add $loopcount 1
  #switch (@speech=2) {
    // Turn the sentence into stutter speech
    #if (%match( %i, %concat( "^({", @stutterlist, "})*"), $matched)) {#if (%random( 1, @st_relay)=1) {
        //Need to change intensity of the stutter when it is a question or exclamation point at the end of the sentence
        $word = %concat( $matched, "-", $matched, "-", %i)
        $NewSentence = %replaceitem( $word, $loopcount, $sentence)
        }}
    } (@speech=3) {#IF (%iskey( @OldEnglish, %trim( %i))) {$NewSentence =%concat( $NewSentence, %db( @OldEnglish, %trim( %i)), " ")} {$NewSentence=%concat( $NewSentence, %i)}} (@speech=4) {
    // Turn the sentence into a lisp speech
    #if (%match( %i, %concat( "({", @lisplist, "})"), $matched)) {
      $word = %replace( %i, $matched, "th")
      $NewSentence = %replaceitem( $word, $loopcount, $sentence)
      }
    }
  }
;Remove extra space in string list
$NewSentence = %replace( $NewSentence, " |", "|")
;Replace pipe symbols with space to display remaining input
$NewSentence = %expandlist( $NewSentence, " ")
;********* Display the finished output ***********************
#if (($channel =~ "shout" || $channel =~ "yell") && ($emphasis)) {
  #print <color red>You can't use emphasis with shout</color>
  #return {$channel $NewSentence}
  }
{#return {$channel $person %quote( $emphasis) $NewSentence}}]]></value>
    <arglist>$channel,$input</arglist>
    <notes>This function is used to create the type of speech impairment the player would like to use.
Speech Variables:
Command Line =1
Stutter = 2
Old English = 3
Lisp = 4
Hissing = 5</notes>
  </func>
</cmud>

Gurus. Can you look at this and see if you can see any reason this is happening.
Oh yeah here is my trigger the calls the function.
Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger type="Command Input" priority="210">
    <pattern>^say(*)</pattern>
    <value>#local $input
$input = %1
#send @SpeechType(say,$input)
#noinput</value>
  </trigger>
</cmud>
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Oct 25, 2010 1:33 pm   
 
Sorry I'm late, but did you actually try Complex's idea? %match works just like a trigger pattern.
Using a database variable in a trigger pattern matches against the _keys_ of the variable, as if it were a stringlist.
So, Complex's method should work, and is much simpler than any of the other ideas.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Oct 25, 2010 2:23 pm   
 
Rahab wrote:
Sorry I'm late, but did you actually try Complex's idea? %match works just like a trigger pattern.
Using a database variable in a trigger pattern matches against the _keys_ of the variable, as if it were a stringlist.
So, Complex's method should work, and is much simpler than any of the other ideas.


Rahab,
I tired the %dbkeys() function and I can work. The issue I am having is that I can't get it to match the word at the end of the sentence because of the punctuation. I tried several ways to get rid of any punctuation but I must I can't get the expression correct. Also I still have the issue with the function sometimes eating the sentence variable in the stutter evaluation in the function as I stated above. Any help would be appreciated.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Oct 25, 2010 4:59 pm   
 
Does the problem happen only with stuttering (@speech=2), or only with Old English (@speech=3), or both?
The %match() statements for 2 and 3 are not equivalent. 2 has an asterisk in it to catch any punctuation or other stuff at the end of the word.
Actually, I would change that asterisk to %q, which specifically matches any punctuation or the end of the line.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Oct 25, 2010 8:50 pm   
 
Hurray!!! I fixed my script!! I think I will be posting the updated script to the package library in a few days! Now I need to do a hissing for serpent characters.

If anyone has any suggestions on more speech types just PM me!
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net