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
TesterOfLimitz
Novice


Joined: 02 Jun 2007
Posts: 37

PostPosted: Mon Aug 20, 2007 4:57 am   

Problem with a multistate trigger using the #SUB command
 
Ive got a mutlistate trigger (this is the third state) that checks to see if i send the command to touch a tree tattoo, then looks for me actually touching it, then checks for the cure (the line im having a problem with). As is, it works with the code like this
Code:
Pattern:
 (*)
Code:
#if (%db( @treeable, %1)) {
  #delkey afflicted %db( @treeable, %1);#gag;
  #say ~<color green>%db( @treeable, %1)~</color>
  } {#loopdb @treeable {#delkey afflicted %val}}

But, I get a small delay between the gag and the say, causing my text to jump. So I thought a simple solution would be change it from using #GAG and #SAY to #SUB. However when I use this code:
Code:
Pattern:
(*)
Code:
#if (%db( @treeable, %1)) {
  #delkey afflicted %db( @treeable, %1)
  #sub %concat("~<color green>",%db( @treeable, %1),"~</color>")
  } {#loopdb @treeable {#delkey afflicted %val}}


This is what is shown on screen (after healing a broken leg):

Quote:
Broken Right Leg(%db( @treeable, %1)) {
#delkey afflicted %db( @treeable, %1);#sub %concat("",%db( @treeable, %1),"")
} {#loopdb @treeable {#delkey afflicted %val}}


And i must note that the Broken Right Leg is correct, and its colored correctly, but all of the code at the end is the problem.

Ive tested this using an almost exact copy with a single state trigger, and it works perfectly (I thought it might be a problem with using #Sub within an #IF statement) so i really have no idea what to do. Any and all help is greatly appreciated!!
-----------------------------------------------------------------------------------
Edit: The datarecords that it checks against looks something like this:
Quote:
#va treeable %null
#addkey treeable "The bones in your right leg mend." "Broken Right Leg"
#va afflicted %null
#addkey afflicted "Broken Right Leg" 1
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Mon Aug 20, 2007 7:16 am   
 
#SUBS {everything inside here, enclosed by the parentheses}

I don't know if that will solve the problem, but I do know I've had problems with subs in the past when I don't use the parentheses.
_________________
Athlon 64 3200+
Win XP Pro x64
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Aug 20, 2007 9:13 am   
 
Just to be picky - from the point of view of the parser, parenthesis are brackets (). The curly ones {} are called braces.

As for the #sub command, your example isn't failing for me in the same way, but it's not colouring properly. Might have something to do with your MXP syntax being wrong - <> are no longer special characters and so don't need escaping. See here.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
TesterOfLimitz
Novice


Joined: 02 Jun 2007
Posts: 37

PostPosted: Mon Aug 20, 2007 3:18 pm   
 
A little more info:

Ive been running a test trigger with this code:
Code:
#if (%db(@test,%1)) {#delkey test2 %db(@test,%1);#sub %concat("Tested Sub")} {#loopdb @test {#say %val}}

It works fine, so i think it has something to do with the multistate: The trigger in question looks like this
Code:
State 1: Command Input: touch tree
State 2: Within Lines: You touch a tree tattoo.
State 3: Within Lines: (*)                   <---- Problem trigger.

Also, it still deletes the key as expected, it only adds in all the code after the sub. I tried using the braces {} around the entire sub #sub {%db(@treeable,%1)} and it actually showed the "Broken Leg" then the entire code afterwards (whereas before it didnt show the #if)

Anyways, this really has me stumped, and I appreciate all the help :)
Reply with quote
TesterOfLimitz
Novice


Joined: 02 Jun 2007
Posts: 37

PostPosted: Thu Aug 23, 2007 12:55 am   
 
Been tinkering with this script a bit more, and I cant find a way to fix it....The test works perfectly.......but the actual usage trigger still shows this on firing

Broken Right Leg#if (%db( @treeable, %1)) {
#delkey afflicted %db( @treeable, %1);#sub %concat("",%db( @treeable, %1),"")
} {#loopdb @treeable {#delkey afflicted %val}}
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Aug 23, 2007 1:45 am   
 
One thing I will suggest is using the Reformat Script option to see if that formats the script as you'd expect. Make a copy of the script before doing this, because if it turns out that there is an error here, it'll probably screw up the spacing.

I say this because of the weird spacing on your last line. #IF is normally spaced like so:

Code:
#if {
  true-command
  true-command
} {
  false-command
  false-command
}

And the way you have it, with the closing brace of the true-commands indented may be causing it to be parsed incorrectly. If a line is indented, CMUD sees it as a continuation of the previous line, making things like this work

Code:
#say Hello
  from
  a
  few
  lines
  down!

and this might be affecting your #IF.

Using Reformat Script should expose this problem, because it'll format your script correctly if it's parsing it correctly. You could also make the change manually and see if that helps.

If this is the problem, I'm very surprised that it didn't cause an error when the script was compiled. It might be possible to study the compiled code and see if it's going wrong at the indented brace, but it'll probably be much easier just to change it and see if it starts working.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
TesterOfLimitz
Novice


Joined: 02 Jun 2007
Posts: 37

PostPosted: Thu Aug 23, 2007 3:00 am   
 
Ok, i tested the Auto-format, and its still giving me problems, but testing a little more, it seems its a problem with the pattern, not the script itself......The original test worked fine. when I used
Code:
#va test %null
#addkey test a 1
Pattern: This is (*) test.
Code: #if (%db(@test,%1)) {#delkey test2 %db(@test,%1);#sub %concat("Tested Sub")} {#loopdb @test {#say %val}}
#alias {Test} {#say This is a test.}

But messes up (in the same exact way) when i use:
Code:

#addkey test "This is a test" 1
Pattern: (*)
Code: #if (%db(@test,%1)) {#delkey test2 %db(@test,%1);#sub %concat("Tested Sub")} {#loopdb @test {#say %val}}
#alias {Test} {#say This is a test.}


The only thing that changed was the pattern between the two (and the data record entry) Perhaps if I used a Regex trigger for it, it would work out, but im hooooorible with Regex, and have no idea where to begin Crying or Very sad
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Aug 23, 2007 3:10 am   
 
Try your new pattern with a mocked-up single-word key and see if that's making the difference. It's possible there's a bug in there somewhere.

If not, if you give us some sample lines I'm sure we can give you a regex that'll match. Regexes are actually really similar to Zugg's syntax - there's a reference for them here.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
TesterOfLimitz
Novice


Joined: 02 Jun 2007
Posts: 37

PostPosted: Thu Aug 23, 2007 5:20 am   
 
Worked fine after replacing (*) with (%w) and using a single word variable...test looked like this:
Code:

State 1: Command Input: Touch tree
State 2: Within Lines: You touch a tree of life tattoo.
State 3: Within Lines: (%w)
Code for state 3:                                     <==== Note nothing has changed on the actual code itself, only the Pattern
#if (%db( @treeable, %1)) {
  #delkey afflicted %db( @treeable, %1)
  #sub %concat("~<color green>",%db( @treeable, %1),"~</color>")
  } {#loopdb @treeable {#delkey afflicted %val}}


#addkey treeable One Two
#alias {Test} {touch tree;#say;#say You touch a tree of life tattoo.;#say One}



Used correctly colored sub, no flub up...so its definitely gotta be a problem with using (*)

And the keys vary alot for the @treeable variable, as its a list of everything that could possibly be cured via the tree tattoo. Things like:
Quote:
Your right leg feels healthier.
Thank Maya! Your clumsiness has been cured
Aaaahhh. No one is out to get you after all.
Reply with quote
TesterOfLimitz
Novice


Joined: 02 Jun 2007
Posts: 37

PostPosted: Fri Aug 24, 2007 1:00 am   
 
Can anyone else check and see if thats what's causing the problem? Im not sure if its a bug, or if its just a problem with my individual setup.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Aug 24, 2007 1:08 am   
 
My test code looked like this:

Code:
#trig {touch tree} {} "" {input}
#cond {You touch a tree of life tattoo.} {}
#cond {(*)} {#if (%db( @treeable, %1)) {
  #delkey afflicted %db( @treeable, %1)
  #sub %concat("~<color green>",%db( @treeable, %1),"~</color>")
  } {#loopdb @treeable {#delkey afflicted %val}}}

#addkey treeable One Two
#alias {test} {#addkey afflicted Two value;touch tree;#say;#say You touch a tree of life tattoo.;#say One}

And I got the error described. When the pattern was changed to (%w), the trigger fired properly but the text wasn't coloured.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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