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 9:32 pm   

Weird %match issue
 
I have a for loop with %match inside a #switch. What is weird the match is acting differently in each case.
Here is the for loop:
Code:
#forall $sentence {
  #add $loopcount 1
  #switch (@speech=2) {
    // Turn the sentence into stutter speech
    #if (%match( %i, %concat( "^({", @stutterlist, "})*"), $matched)) {
    #print Stutter match: $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)
        $sentence = %replaceitem( $word, $loopcount, $sentence)
        }}
    } (@speech=3) {
     #print Value of i: %i
    // Turn the sentence into Old English speech
    #if (@OldEnglish = "%1") {
    //#if (%match( %i, %concat( "^({", @OldEnglish, "})*"),  $matched)) {
    #print Match
    //  $word = %replace(%1, $matched, @OldEnglish.%i)
    //  $sentence = %replaceitem( $word, $loopcount, $sentence)
    }
    } (@speech=4) {
     // Turn the sentence into a lisp speech
     #if (%match( %i, %concat( "({", @lisplist, "})"), $matched)) {
      #print Lisp match: $matched
       $word = %replace( %i, $matched, "th")
      $sentence = %replaceitem( $word, $loopcount, $sentence)
      }
    }
  }

Now the two string lists referenced in the loop are:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <var name="stutterlist" type="StringList">
    <value>th|ch|st|tr|bl|br|bl|sp|t|h|g|i|c|l|j|y|d|an|w</value>
    <json>["th","ch","st","tr","bl","br","bl","sp","t","h","g","i","c","l","j","y","d","an","w"]</json>
  </var>
</cmud>

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <var name="lisplist" type="StringList">
    <value>s|z|sh|ch|j</value>
    <json>["s","z","sh","ch","j"]</json>
  </var>
</cmud>

This is the sentence being passed:
Code:
say This is a test. You are now wishing it so.

If you look at the two %match lines in the #switch they are very similar but the $matched variable outputs quite differently.
When I hits the stutterlist the $matched displays correctly. It shows:
Code:

Stutter match: Th
Stutter match: i
Stutter match: t
Stutter match: Y
Stutter match: w
Stutter match: i
say   Th-Th-This is a t-t-test. Y-Y-You are now wishing i-i-it so.

When it tries the same sentence with the lisplist. It shows:
Code:

Lisp match: s  = Thith This|is|a|test.|You|are|now|wishing|it|so. = |is|a|test.|You|are|now|wishing|it|so.
Lisp match: s  = ith This|is|a|test.|You|are|now|wishing|it|so. = This||a|test.|You|are|now|wishing|it|so.
Lisp match: s  = tetht. This|is|a|test.|You|are|now|wishing|it|so. = This|is|a||You|are|now|wishing|it|so.
Lisp match: sh  = withing This|is|a|test.|You|are|now|wishing|it|so. = This|is|a|test.|You|are|now||it|so.
Lisp match: s  = tho. This|is|a|test.|You|are|now|wishing|it|so. = This|is|a|test.|You|are|now|wishing|it|
say   This is a test. You are now wishing it so.


Is this a bug or am I not see something?
_________________
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: Sat Oct 23, 2010 9:40 pm   
 
Zugg,
I think this is a bug... The reason is I changed the first match to be just like the second match and it displayed correctly. Here is the output.
Code:

Stutter match: s
Stutter match: s
Stutter match: s
Stutter match: sh
Stutter match: s
say   This s-s-is a test. You are now wishing it s-s-so.
_________________
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 10:07 pm   
 
Your 5th line up from the bottom in the code you've posted is indented by one character. For me, using mud 3.31 this is causing that line to be included in the #print command and is preventing it from setting the local variable $word correctly.

This line:
$word = %replace( %i, $matched, "th")

When the line is formatted as you have it, I get this output:
Code:
Lisp match: s  = thay
Lisp match: s  = Thith
Lisp match: s  = ith
Lisp match: s  = tetht.
Lisp match: sh  = withing
Lisp match: s  = tho.


When the excess space is removed, I get this output:
Code:
Lisp match: s
Lisp match: s
Lisp match: s
Lisp match: s
Lisp match: sh
Lisp match: s
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sat Oct 23, 2010 10:13 pm   
 
I am not even talking about local variable word. I am talking about the match line.
Okay..That isn't it because the print statement is before that line. I even did a reformat script and I still get the error.

NOTE: I manually moved the lines around to line up differently like you did it and then it work. That tells me there is an error in the editor.
_________________
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)

Last edited by darmir on Sat Oct 23, 2010 10:20 pm; edited 1 time in total
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Sat Oct 23, 2010 10:18 pm   
 
Go in and manually remove all indententation from the lines:
Code:
       $word = %replace( %i, $matched, "th")
      $sentence = %replaceitem( $word, $loopcount, $sentence)

where hey are contained in the (@speech = 4) switch. (The fourth and fifth lines from the bottom of the code you posted) then let Cmud reformat your code by pressing Ctrl+M

Then try it
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sat Oct 23, 2010 10:23 pm   
 
DraxDrax wrote:
Go in and manually remove all indententation from the lines:
Code:
       $word = %replace( %i, $matched, "th")
      $sentence = %replaceitem( $word, $loopcount, $sentence)

where hey are contained in the (@speech = 4) switch. (The fourth and fifth lines from the bottom of the code you posted) then let Cmud reformat your code by pressing Ctrl+M

Then try it

You posted this as I was editing my previous post.. There must be a minor bug then in the editor.
_________________
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 10:36 pm   
 
I believe what you've found is a feature of the way Cmud parses things, not an error, though I might be mistaken about that. By indenting a line by one character that line is concatentated on to the previous line, so:
Code:
#SAY Line one
 line two
 line three

Parses very differently from:
Code:
#SAY Line one
line two
line three

Copy/paste those to your command line in Cmud and try them.

If you mean to do it, it's a neat feature, but you found it without meaning to.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Oct 25, 2010 5:07 pm   
 
Yes, DraxDrax is correct on this. Proper indentation in CMUD is extremely important. Sort of like in Python.
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