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
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sat Apr 05, 2008 3:28 pm   

Another Broken Trigger
 
This worked before:

Code:

#REGEX sleep {^You go to sleep.*(\b\w+)\.$} {posn=sleep;bed=%1} {General Triggers}


I think most of you remember it. But now it doesn't work, I deleted and reentered, still no cigar.
Reply with quote
cazador
Apprentice


Joined: 08 Dec 2005
Posts: 108

PostPosted: Sat Apr 05, 2008 3:54 pm   
 
try ^You goto sleep\. intstead
With the .* you are triggering on everything after the You go to sleep.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Sat Apr 05, 2008 3:59 pm   
 
It should help to use .*? instead of just .* in this case. You don't want a greedy match to eat up the characters you're trying to capture. Also, the \b can go outside the parentheses, as you only need to capture the word and not the word boundary.


Last edited by Larkin on Sat Apr 05, 2008 4:36 pm; edited 1 time in total
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat Apr 05, 2008 4:07 pm   
 
I pasted your trigger into the command line and it works for all the Test cases you posed in your original thread.

Quote:
You go to sleep on a soft bench.
You go to sleep on a soft, white cloud.
You go to sleep on a black silk-encased mattress.
You go to sleep on a pile of pillows and blankets.


In each case the trigger fired and the bed variable was populated with the last word before the period ie bench ,cloud, mattress or blankets.
So when you say it doesn't work what exactly is the problem?
Is the trigger not firing at all? Is the bed variable being populated with the wrong value?
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sat Apr 05, 2008 5:01 pm   
 
It fails on you go to sleep.

You go to sleep.

fails
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Sat Apr 05, 2008 5:36 pm   
 

Quote:
This worked before:...
Great! Evidently it was still working just not as you really wanted.
Quote:
But now it doesn't work, I deleted and reentered, still no cigar.
The only part of this that is correct is that CMud will not run out and get you a cigar from the cigar shop. I do have CMud make my morning coffee, toast and scrambled eggs were beyond its abilities. We have tried to Zugg into adding that functionality though, and I will have a serious discussion with him about cigars.

Quote:
So when you say it doesn't work what exactly is the problem?
Is the trigger not firing at all? Is the bed variable being populated with the wrong value?
Thank you Dharkael. It is quite sad that after the amount of help chamenas has received on these forums he still needs to be asked such questions in order for us to help him.

And here is your answer, since we finally know what you wanted. Also since you insist on using regexes, go back and read the very thorough explanation of regex basisc that was in another reply to your inquiries. Also please read some of the links that have been provided to the full regex documentation.
Code:
#REGEX sleep {^You go to sleep.*?\b(\w+)?\.$} {posn=sleep;bed=%1} {General Triggers}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sat Apr 05, 2008 5:53 pm   
 
Following the recent trend for regex effeciency...
Code:
^You go to sleep(?:.*\b(\w+))?\.$


Larkin's suggestion of putting the \b outside of the capturing parens is a great one it appears to be more effecient.
His suggestion of putting changing *. to *.? actually makes the pattern less effecient,
rather than grabbing everything to the end of the line and then backtracking for the period and the last word,
it forces the pattern to backtrack for each character after sleep.
For the text "You go to sleep on a pile of pillows and blankets." it triples the number of steps required for a match.

EDIT:The one below is even better in regexes its amazing how a slight alteration can have such a large affect on the effectiveness
of your expression "..with great power..."
Code:
^You go to sleep.*\b(\w+)?\.$
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Apr 06, 2008 12:44 am   
 
Well, I'd need not ask so many questions if I had the time to properly understand everything I've been given, but, alas, college has me working on other things. It's why I like to understand what I'm getting before I use it, but my short time has forced me to just take before fully understanding. What's particularly irksome though is that all of these triggers were good, they were fine, they worked, and now for some reason they don't. It's not like I've done anything different. In any case, another one is failing.

Pattern: ^You are thirsty.$

#IF (@posn="wake") {
#5 {#send "drink decan"}
} {
#send rest
#5 {#send "drink decan"}
#send sleep
}


for some reason, even though the bed variable is empty and the posn one says wake, it insists on putting me asleep every single time. As with the last problem, this trigger worked before, and had now suddenly decided to act up. Knowing computers, they do not just decide to do that, but I don't know the script enough to know what I did wrong.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Sun Apr 06, 2008 1:54 am   
 
Your new problem sounds like a classic issue of having 2 variables with the same name. The easiest way to determine if that is actually the case is to open your session offline. Then enter at the command line
Code:
#VAR;#SHOW {-----};#SCROLL " posn"
This will display all the variables, then pick through that display for those starting with "posn" and redisplay thier information at the bottom.

If you have 2 or more posn variables then that is the problem with your thirsty trigger. You would have to find out why you have the extra(s) after you delete them.

I really am not bothered in the least by how many questions you ask. That is what this forum is here for, and answering questions is a major part of why I come to this forum.

I am personally irritated by how often you forget to actually ask a question. Your original post for this topic is a rather nice example of there being no question asked. When that is compounded by a lack of even stating how something is wrong, what you want it to do, what you expect it to do, what it is actually doing then the post is quite pointless. Again the original post of this topic is a great example of what not to do.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Apr 06, 2008 2:48 am   
 
Code:
Variables:
  bed                 (Literal)     General Variables
  posn                (Literal)     General Variables
  void_count          (Auto)        0
  tnl                 (Auto)        4381
-----
  posn                (Literal)     General Variables


Edit by Vijilante: added code tags to preserve display. Used mind reader skill to and wrote in all the words chemenas forgot to write.

[mindreader]No duplication of variables. What should I look for next?[/mindreader]
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Sun Apr 06, 2008 12:15 pm   
 
That display clearly shows that the value of your posn variable is "General Variables", and not "wake". It would appear that one or more of your assignments to the variable is/was incorrectly structured. You also seem to have the same problem with an assignment to the bed variable.

I am guessing that "General Variables" was meant to be a class, but it got stored into the default field for the variables. Either remove the default value and uncheck the Use default or set proper defaults for the variables. Bed should probably have a null default, while posn might need to maintain its value between sessions.

These incorrect assignments are likely what is causing you intermitten problems with your scripts.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Apr 06, 2008 2:42 pm   
 
Well, that's easy to fix:

#VAR bed " " " " {General Variables}
#VAR posn " " " " {General Variables}


I know that if I don't touch the variable it should stay where it was from session to session. Is the only way to clear it to use the onConnect function to do so? Also, I see a database function in CMUD, can I use that to store data too?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sun Apr 06, 2008 3:27 pm   
 
I'm not sure what you mean by not touching the variable and it staying where it was. If you mean that the value will stay the same, that's not true - you've specified a default value for the variable there, which it'll be reset to when your session's opened. If you mean to use no default, use _nodef as the default parameter of the #var command. If you want it set to some value when the session starts, specify that as the default - you don't need to use OnConnect at all, then.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sun Apr 06, 2008 3:40 pm   
 
Ah. Thank you.
_________________
Listen to my Guitar - If you like it, listen to more
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