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
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Fri Jun 13, 2003 3:16 am   

Help with a temp trigger running multiple times?
 
I'm having problems with a script that is supposed to parse the output from the 'score' command and tell me which spells I'm currently missing for my selected scenario. The scipt is kinda large so I'll only post what seems to be the key part here. The problem I'm having is that the report message sometimes shows up numerous times (and sometimes not). Here's an example of the error:

quote:

310h 381m 70v> sc
You are 50 years old.
You have 310(310) hit, 381(388) mana and 70(70) movement points.
You have scored 0 exp, and have 10119 gold coins.
You have been playing for 16 days and 13 hours.
You are carrying 5 items, totaling 106 pounds.
You have 19 of 20 saveable valuable items.
You have attained : (mage 20) (warrior 6) (cleric 20) (thief 11).
You belong to the Knights of the Realm.
You are standing.
You can detect magic.
You can detect living creatures.
You can detect invisible.


















310h 381m 70v>
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury
MISSING: farsee, strength, vitality, fury

310h 381m 70v>



Here's part of the script where I would expect to find the problem. Let me know if you need more to diagnose...



#CLASS {spell_tracker_script}
#ALIAS spell_tracker_parse_current_spells {
#VARIABLE spell_tracker_current_spells {} {} {spell_tracker_script|spell_tracker_working_vars}
#VARIABLE spell_tracker_missing_spells {} {} {spell_tracker_script|spell_tracker_working_vars}
#FORALL @spell_tracker_current_spells_text {#LOOPDB @spell_tracker_score_spell_messages {#IF (%val="%i") {
#ADDITEM spell_tracker_current_spells %key
#ABORT
}}}
#FORALL %db( @spell_tracker_scenarios, @spell_tracker_current_scenario) {#IF (! %ismember( %i, @spell_tracker_current_spells)) {#ADDITEM spell_tracker_missing_spells {%i}}}
#IF (! %null( @spell_tracker_missing_spells)) {
#CR
#ECHO MISSING: %expandlist( @spell_tracker_missing_spells, ", ")
}
}
#TRIGGER "SPELLTEXTTRIGGER" {^You are {sleeping|resting|sitting|standing}.$} {
#VARIABLE spell_tracker_current_spells_text {} {} {spell_tracker_script|spell_tracker_working_vars}
#TEMP SPELLTEXTTRIGGERDONE {$} {
#STATE SPELLTEXTTRIGGER 0
spell_tracker_parse_current_spells
} spell_tracker_script
}
#CONDITION {^(*)$} {#ADDITEM spell_tracker_current_spells_text {%1}} {looplines|param=30}
#MENU {Spell Tracker} {} "" {spell_tracker_menu}
#CLASS 0


The forum doesn't seem to show it, but there are a lot more blank lines after the score output before my #echo's show up.

Also, if anyone knows how to make my #echo's show up immediately after the score output (before my next prompt) that would be great, too.

Thanks in advance.

Eupher
Reply with quote
CDS
Beginner


Joined: 31 May 2003
Posts: 15
Location: USA

PostPosted: Fri Jun 13, 2003 5:59 am   
 
Hi,

How about replacing

#TEMP SPELLTEXTTRIGGERDONE {$} {
with
#TEMP SPELLTEXTTRIGGERDONE {^$} { <-- I use a caret to be sure
#T- "SPELLLINESTRIGGER"

and

#CONDITION {^(*)$} {#ADDITEM spell_tracker_current_spells_text {%1}} {looplines|param=30}
with
#TRIGGER "SPELLLINESTRIGGER" {^(*)$} {#ADDITEM spell_tracker_current_spells_text {%1}}

It should read your whole list whether there are 0, 30, or 1000 items. Then the first blank line will kick it off. I have no experience with looplines, so I'm not sure if it can cause the extra lines you mentioned. This version should work and it eliminates looplines as a potential source of the problem though.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Jun 13, 2003 11:46 am   
 
First lets eliminate some of the extra loops, they are making the script too slow. We change your capturing condition to convert them as they are captured and that gets rid of 2 loops:
#CONDITION {^(*)$} {#ADDITEM spell_tracker_current_spells {%db(@spell_tracker_score_spell_messages, "%1")}} {looplines|param=30}

This will require that you blank the correct variable in the 0 state of the trigger, and while were ate at it might as well do a little more initialisation and processing during the capture to eliminate the 3rd loop...

#TRIGGER "SPELLTEXTTRIGGER" {^You are {sleeping|resting|sitting|standing}.$} { #VARIABLE spell_tracker_current_spells {} {} {spell_tracker_script|spell_tracker_working_vars};#VARIABLE spell_tracker_missing_spells {%db( @spell_tracker_scenarios, @spell_tracker_current_scenario)} {} {spell_tracker_script|spell_tracker_working_vars};#TEMP SPELLTEXTTRIGGERDONE {$} { #STATE SPELLTEXTTRIGGER 0;spell_tracker_parse_current_spells} spell_tracker_script};#CONDITION {^(*)$} {#ADDITEM spell_tracker_current_spells {%db(@spell_tracker_score_spell_messages, "%1")};#DELITEM spell_tracker_missing_spells {%db(@spell_tracker_score_spell_messages, "%1")}} {looplines|param=30}

And now all loops are eliminated. The alias can be changed to just do the display, or you can put that directly into the TEMP trigger.
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Fri Jun 13, 2003 4:21 pm   
 
Thanks for the help folks. I decided to try Vijilante's suggestion since I wanted to keep using the new trigger type and figure out what was wrong.

The suggestion was great, it definitely made the script faster. It was so fast that instead of just spitting out a dozen or so blank lines and spell messages, zmud just croaked on it and said I had an endless loop. :)

I took the #CR out of the alias that echos the missing spells and it seems to work fine now. I'm not sure if that's a bug or not... it seems like you should be able to use a #CR in that situation. It's like the #STATE command isn't getting executed when it's called or something?

Thanks again,
Eupher
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Jun 13, 2003 10:34 pm   
 
Did you change the alias to remove everything else? Yeah I think you did if your complaining about it being too fast....

After a little testing it appears that TEMP triggers that have long slow loops in them cause problems. Thanks for finding the bug.
Reply with quote
eupher
Apprentice


Joined: 18 Jan 2001
Posts: 116
Location: USA

PostPosted: Sat Jun 14, 2003 2:10 am   
 
I'm not sure I was complaining about it being too fast... the old slow way still showed the bug. The problem is that the second pattern (state 1) of the trigger is a blank line, and the temp trigger was attempting to change the state back to 0 and THEN echo a blank line... but that echo'd blank line was getting caught because the state had not been updated yet.

I'm not really sure that has anything to do with the speed of the statements in the temp trigger, but I could be wrong about what's happening.

Thanks again,
Eupher
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Jun 14, 2003 6:44 am   
 
I would actually suggest eliminating the temp trigger. ^*$ which is the pattern for your trigger should match a blank line. Using an #IF to check for it, shouldn't cost any speed, and will elimante any problems as well as shorten your codebase.
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