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


Joined: 08 Apr 2004
Posts: 103
Location: USA

PostPosted: Sun Oct 18, 2009 2:45 am   

Multistate triggers
 
I am trying to make a multistate trigger that has multiple possibilities off of one line.
Example:
Code:

You eat a piece of kelp.
You no longer have asthma.

Code:

You eat a piece of kelp.
You no longer have weariness.


Think is.. I'd like to put it all under the one trigger You eat a piece of kelp.. Then check for all the others. Any way to do this?
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Sun Oct 18, 2009 3:00 am   
 
You could, with one really large trigger pattern, but a better way to do it would be this:

#trigger {^You eat a piece of kelp.$} {#var curing 1}

#trigger {^You no longer have asthma.$} {#if (@curing == 1) {do stuff}}

#trigger {prompt pattern} {#var curing 0}
Reply with quote
orphean
Apprentice


Joined: 21 Oct 2008
Posts: 147
Location: Olympia, WA

PostPosted: Sun Oct 18, 2009 3:17 am   
 
Seems to me that using Cmud's support for multistate triggers makes more sense here.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger priority="20">
    <pattern>You eat a piece of kelp.</pattern>
    <trigger>
      <pattern>You no longer have (*).</pattern>
    </trigger>
  </trigger>
</cmud>


In this case the inner trigger is only checked if the preceding line matches the outer trigger. In this example, the ailment would be in %1 for the inner trigger's script which you could then easily check with a switch statement.
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Sun Oct 18, 2009 3:28 am   
 
With those specific examples yes, but it looks like he's playing an IRE mud. So, I assumed they were a simplification of the actual messages.
Reply with quote
Dyron
Apprentice


Joined: 08 Apr 2004
Posts: 103
Location: USA

PostPosted: Sun Oct 18, 2009 3:34 am   
 
General is correct.. the exact messages are as follows:


You eat a piece of kelp.
Your limbs strengthen and you feel stronger.


You eat a piece of kelp.
Your bronchial tubes open up and your asthma is cured.
Reply with quote
Dyron
Apprentice


Joined: 08 Apr 2004
Posts: 103
Location: USA

PostPosted: Sun Oct 18, 2009 3:36 am   
 
You eat a bellwort flower.
Ahhhh. The freedom to be stingy again

Incase you think they all begin with your.. sadly, they don't
Reply with quote
orphean
Apprentice


Joined: 21 Oct 2008
Posts: 147
Location: Olympia, WA

PostPosted: Sun Oct 18, 2009 3:44 am   
 
Fair enough, but I still think using a multistate trigger simplifies matters in this case. For example,

Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger name="curetrigger" priority="20">
    <pattern>You eat a piece of kelp.</pattern>
    <trigger prompt="true">
      <pattern>(*)</pattern>
      <value>#if (%match(%1, "You no longer have (%w).", $Ailment) <> 0)
{
  #show Do what needs to be done here.
  #state curetrigger 1
}
{
  #state curetrigger 0
}
</value>
    </trigger>
  </trigger>
</cmud>


With this example, once 'You eat a piece of kelp.' is matched the trigger will stay in it's second state until cmud receives a line that fails to match You no longer have (%w).

So this would match

Code:

You eat a piece of kelp.
You no longer have asthma.
You no longer have weariness.
You no longer have mumps.


etc, and let Dyron do whatever it is he wants to do on a line by line basis.

If he just gets 'You eat a piece of kelp' and the kelp does nothing then the inner state immediately fails and that's that.

What's so great about Cmud is that it is robust enough where there is multiple ways of doing nearly anything. This way seems more compact and cleaner to me. :)
Reply with quote
orphean
Apprentice


Joined: 21 Oct 2008
Posts: 147
Location: Olympia, WA

PostPosted: Sun Oct 18, 2009 3:52 am   
 
Dyron wrote:
You eat a bellwort flower.
Ahhhh. The freedom to be stingy again

Incase you think they all begin with your.. sadly, they don't


Well in this case I would change the match to be more general and use a switch.

Code:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <trigger name="curetrigger" priority="2240" regex="true">
    <pattern>You eat a (.*).</pattern>
    <trigger prompt="true">
      <pattern>(*)</pattern>
      <value>#switch (%1)
  ("Ahhhh. The freedom to be stingy again")  { #show do whatever
                                               #state curetrigger 1}
  ("Your bronchial tubes open up and your asthma is cured.")  { #show do whatever
                                               #state curetrigger 1}
  ("Your limbs strengthen and you feel stronger.")  { #show do whatever
                                               #state curetrigger 1}
                                              { #state curetrigger 0 }

</value>
    </trigger>
  </trigger>
</cmud>


This will match You eat a <anything>. Then as you need to match other things you can just add them to the switch.

Edit: Really just do whichever you like better. This road and GeneralStonewall's road both lead to Rome as it were.
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Sun Oct 18, 2009 3:57 am   
 
Then yes, my suggestion would be:

#trigger {You eat a piece of kelp.} {#var curing_with kelp}
#trigger {You eat a bellwort flower.} {#var curing_with bellwort}

#trigger {Your limbs strengthen and you feel stronger.} {#if (@curing_with) {do stuff}}
#trigger {Ahhhh. The freedom to be stingy again } {#if (@curing_with) {do stuff}}

#trigger {prompt pattern} {#var curing_with ""} "" "prompt"

Also, you could throw in alternative cures as well:

#trigger {You use a tree tattoo} {#var curing_with tree}

Then you have the added capacity of knowing what you're curing with. Which you could later build on.
Reply with quote
Dyron
Apprentice


Joined: 08 Apr 2004
Posts: 103
Location: USA

PostPosted: Sun Oct 18, 2009 5:02 am   
 
No idea why this is being so difficult.. On that switch.. I want to do this


switch (%1)
(H~:(%d)) {#exit}
("Ahhhh. The freedom to be stingy again") {#delitem afflictions "generosity"}
("Your bronchial tubes open up and your asthma is cured.") {#delitem afflictions "asthma"}
("Your limbs strengthen and you feel stronger.") {#delitem afflictions "weariness"}

In bold is the part that's messing up.. it doesn't register it right for some reason..
Reply with quote
orphean
Apprentice


Joined: 21 Oct 2008
Posts: 147
Location: Olympia, WA

PostPosted: Sun Oct 18, 2009 5:37 am   
 
From the #SWITCH documentation:
Code:
A shortcut exists for switch commands that check a range of values of a single variable:
Code:
#switch (@a)
  (0) {a is 0}
  ("blueberries") {a is "blueberries"}
  ("") {a is an empty string}
  {nothing matched}


I'm guessing the shortcut matching isn't capable of the more complex match. Since the () blocks can contain any arbitrary expression try changing "H~:(%d))" to:

Code:

(%match(%1, H~:(%d)) != 0) { #exit }
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sun Oct 18, 2009 5:05 pm   
 
In that style of switch, it can only match against exact patterns. If you need to match against a pattern, you will have to use a different style of switch:
Code:

#switch (%match(%1, H~:(%d)) != 0) { #exit }
  (%1 == "Ahhhh. The freedom to be stingy again") {#delitem afflictions "generosity"}
  (%1 == "Your bronchial tubes open up and your asthma is cured.") {#delitem afflictions "asthma"}
  (%1 == "Your limbs strengthen and you feel stronger.") {#delitem afflictions "weariness"}
Reply with quote
Dyron
Apprentice


Joined: 08 Apr 2004
Posts: 103
Location: USA

PostPosted: Sun Oct 18, 2009 8:21 pm   
 
#switch (%1)
("The confusion lifts from your mind and it is clear once again.") {#ADDITEM pendCures "confusion"}
(%match(%1, "Your terrible hatred for (%w) fades.")) {#ADDITEM pendCures "hatred";#say shot}
("Hallucinations cease to plague your mind.") {#ADDITEM pendCures "halluncations"}
("Your hallucinations cease to plague you.") {#ADDITEM pendCures "halluncations"}
("You feel a bit more alert and awake.") {#ADDITEM pendCures "hypersomnia"}
("Sanity returns to you and you are no longer demented.") {#ADDITEM pendCures "dementia"}
("Aaaahhh. No one is out to get you after all.") {#ADDITEM pendCures "paranoia"}
("You put on your happy face and prepare to face the world!") {#ADDITEM pendCures "sadness"}
("You are able to once again control your concentration.") {#ADDITEM pendCures "bloodcurse"}
{#exit}

I couldn't get the Health thing to work with either suggestions, so I just skipped it, but now I run into another problem.
It won't even read the (%w) wild card... I tried match now, but that isn't working either
Reply with quote
orphean
Apprentice


Joined: 21 Oct 2008
Posts: 147
Location: Olympia, WA

PostPosted: Sun Oct 18, 2009 8:32 pm   
 
It's the same problem that Rahab pointed out. The shortcut style of switch can't do complex matching so you need to redo it to the general style that Rahab posted.

Code:

#switch (%match(%1, "Your terrible hatred for (%w) fades.")) {#ADDITEM pendCures "hatred";#say shot}
(%1 == "The confusion lifts from your mind and it is clear once again.") {#ADDITEM pendCures "confusion"}
(%1 == "Hallucinations cease to plague your mind.") {#ADDITEM pendCures "halluncations"}
(%1 == "Your hallucinations cease to plague you.") {#ADDITEM pendCures "halluncations"}
(%1 == "You feel a bit more alert and awake.") {#ADDITEM pendCures "hypersomnia"}
(%1 == "Sanity returns to you and you are no longer demented.") {#ADDITEM pendCures "dementia"}
(%1 == "Aaaahhh. No one is out to get you after all.") {#ADDITEM pendCures "paranoia"}
(%1 == "You put on your happy face and prepare to face the world!") {#ADDITEM pendCures "sadness"}
(%1 == "You are able to once again control your concentration.") {#ADDITEM pendCures "bloodcurse"}
{#exit}
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