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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Wed Oct 08, 2003 7:21 pm   

Trouble with a pattern matching trigger
 
I am trying to use a the following trigger to capture my text, then create a record for each of my skills. The trigger is as follows.


#CLASS {Skills}
#VARIABLE EndLine {>}
#TRIGGER "SkillCatch" {show skills} {#SHOW hi}
##CONDITION {} {#IF (%line =~ "(*):%s(*).") {
#SHOW "%1"
#SHOW "%2"
#ADDKEY "%1" {CL="%2"|NL=0|Synched=true}
}
{#IF (%line =~ "~>") {#SET 2}}} {looplines|param=30}
CONDITION {>} {#SHOW Goodbye}
#CLASS 0


The italicized condition is the focus of my question, and the bolded portion is the code snippet I'm having problems with. The text it should match is as follows


Code:
show skills
attack speed:              Poor.
brawling:                  Poor.
butchering:                Unskilled.
control:                   Not very good.
daring:                    Poor.
farming:                   Unskilled.
fighting:                  Poor.
hiking:                    Unskilled.
language#catfolk:          Average.
language#common:           Average.
language#southern:         Not very good.
multiple attacks:          A tyro.
offensive:                 Poor.
parry:                     Poor.
sword:                     Poor.
thrown:                    A beginner.
wood working:              Poor.
>


The trigger activates on the text fine, however my %1 and %2 of my 2nd state are empty, thus no record is created.

Strangely enough, if I execute the following, %1 and %2 do have the values I expect.

#say wood working: Poor.;#IF (%line =~ "(*):%s(*).") {#SHOW "%1"; #SHOW "%2"}

It prints
Code:
wood working
Poor


Am I missing something simple, or is this by design. How can I reparse the line to get the matched variables that I want?

Vincent
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Oct 08, 2003 8:55 pm   
 
It might be typos.
##CONDITION
{looplines|param=30}CONDITION

This seems a little simpler.
#CLASS {Skills}
#VARIABLE EndLine {>}
#TR SkillCatchOff {^~>} {#T- SkillCatchOff;#STATE Skillcatch 0;#SHOW Goodbye}
#TRIGGER "SkillCatch" {show skills} {#T+ SkillCatchOff;#SHOW hi}
#CONDITION {(*):%s(*).} {
#SHOW "%1"
#SHOW "%2"
#ADDKEY {%replace( "%1", " ", "_")} {CL="%2"|NL=0|Synched=true}
} {looplines|param=99}
#CLASS 0

NOTES:
1. * doesn't match #, so language skills will be in @catfolk instead of @language#catfolk, etc.
2. Since you do two #SHOWs after each match, you triple the number of lines. I increased the Loopline param to 99 to compensate.
3. Spaces aren't really desirable in variable names. I used %replace to get rid of them.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Oct 09, 2003 6:48 am   
 
The ## is a typo, and the SHOW %1 and SHOW %2 were just to make sure I wasn't going crazy because I didn't see those values.

I'm going to try what you said though.

Thanks for the help.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Oct 09, 2003 7:26 am   
 
Thanks that did the trick.

I'm re-learning zMud scripting and I've forgotten alot. :-D Dang Java!
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Oct 09, 2003 8:49 pm   
 
I'm trying to take the script to the next level now. I want to check if the variables exist already. To do this I'm using an if statement, but it doesn't seem to be working. Any advice?

The show statement is just to keep track of what actually gets executed. The bolded if statement always evaluates to false. Is this the best way to check for the existence of a variable when you get the variable name from another variable?

Basically what I'm trying to say is
Code:
if (database record variable exists)
{
 Update the existing variable values
}
{
 Create new database variable record
}


Here's the trigger I'm using.

#TRIGGER "SkillCatch" {show skills} {#T+ SkillCatchOff}
#CONDITION {(*):%s(*).} {
#VARIABLE _temp %replace( "%1", " ", "_") "" "" Skills
#IF ( @{@_temp} ){
#SHOW variable exists
#IF ((%2 = %db( @{@_temp}, CL))) {#SHOW variable should be update}
} {
#show create new variable
#VARIABLE @_temp "" "" Skills
#ADDKEY @_temp {Skill=%1|CL="%2"|NL=0|Synched=false}
}
#UNVAR _temp
#GAG
} {looplines|param=99}
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Oct 09, 2003 10:53 pm   
 
Try using %defined(@_temp). Currently an existing variable with null value would fail the test, why it always fails I can't tell. You might want to use a #SHOW, #ECHO, or even #INPUT to give you an idea why, most likely cause is that _temp does not have the right value.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Thu Oct 09, 2003 11:28 pm   
 
That didn't work either. @_temp is defined. It's the name of a variable for example, if @temp = sword then the variable I want is @sword.

For some reason the expression evaluation @{@_temp}}) doesn't quite go the way it should, even with %define(@{@_temp})

I found a workaround though that seemed to do the trick.

Code:

#VARIABLE check %len( @{@_temp})
#IF (@check) {
  #SHOW variable exists
  #IF ((%2 = %db( @{@_temp}, CL))) {#SHOW variable should be update}
  } {
 #ADDKEY @_temp {Skill=%1|CL="%2"|NL=0|Synched=true}
  }


As an aside, this is part of a bigger script I'll eventually build, since many question will be related should I post additional questions here or start a new thread?
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Oct 10, 2003 1:26 am   
 
#ADDKEY updates the existing variable if one by that name exists, and creates one otherwise. Since you use the same command in either case, do you really need to check whether one exists?

This snippet seems to work. I eliminated a couple spaces from ( @{@_temp} ) and added one between it and the {.

#IF (@{@_temp}) {
#SHOW variable exists
#IF (%2 = %db( @{@_temp}, CL)) {#SHOW variable should be update}
} {
#ADDKEY @_temp {Skill=%1|CL="%2"|NL=0|Synched=true}
}

If @_temp equals "sword" and @sword equals stonecutter
%defined( _temp) shows whether @_temp exists
%defined( @_temp) shows whether @sword exists
%defined( @{@_temp}) shows whether @stonecutter exists
An alias, macro, or path of that name (_temp, sword, stonecutter) would give the same result for each test.

It's usually best to keep related questions to a single thread.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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