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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Sun Nov 04, 2007 3:01 pm   

[2.10] - Pattern matching with Variable String List
 
I am not sure if this is a bug or not.
I have a variable called @containertypes which hold:
bag|backpack|pouch

Now I have a trigger with the pattern is:
{@containertypes}
See screen shot


As you can see the pattern matches.

Now when I run the trigger and check for the value it doesn't check.

Trigger value:
Code:

#echo Hit containertypes.
;#NOOP Check to see if you have the container listed
#echo {%1}

The trigger shows the "Hit containers" echo but it doesn't find %1. I tried %1 with {} and without.
Shouldn't I be able to echo the %1 variable..

My correct full trigger is:
Code:

#IF (%ismember(%1,@containertypes)) {
#ADDITEM havecontainer %1
}
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sun Nov 04, 2007 7:02 pm   
 
There are no brackets in your pattern, and thus no captures. Note that the regex is (?:stuff), which prevents a capture - you'll also see on the trigger testing tab that no captures are displayed. To get a capture, use ({whatever}). Also, you don't need to run %ismember on the result, because the result of that trigger will by definition always be a member of the list.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Nov 05, 2007 12:04 am   
 
Thanks, that worked.
Also you say I don't need to do and %member? Is that something new in cMUD?

One thing I did notice that my ConTypeTrig and FoodTypeTrig are causing an infinite loop. Can you help assist me in figure this out?
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Nov 05, 2007 1:14 am   
 
Nope, it's not new to CMud. If you don't care which item in the list is in %1, then you don't need to check if %1 is a member of the list because the trigger pattern already limits choices to what's in the list. Ergo, if something is in %1 then it is in fact something that is also in your stringlist. However, if you needed to know exactly which item was in %1, you would need to use %ismember() and would most likely be using it in conjunction with #CASE or #SWITCH.

As for your infinite loop issue, we can't tell what's going on without seeing the code for them. In your picture, we only see the two trigger names.
_________________
EDIT: I didn't like my old signature
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Nov 05, 2007 2:07 am   
 
Okay..
Here is the full AutoEat,pkg
Code:

<?xml version="1.0" encoding="UTF-8" ?>
<cmud>
<module name="AutoEat" global="true">
  <uid>{41A6B894-7A16-4B04-BEDE-CAC5E777C471}</uid>
  <class name="AutoEatAliases">
    <alias name="checkcontainers">
      <value>#ADD loopcount 1
#T+ FoodTypeTrig
look in %item( @havecontainer, @loopcount)
#ALARM +@AlarmTime {checkmorecontainers}
</value>
    </alias>
    <alias name="checkmorecontainers">
      <value><![CDATA[#T- FoodTypeTrig
#IF ( %numitems( @havefood) ~> 0 ) {
  get %item( @havefood, 1) %item( @havecontainer, @loopcount)
  eat %item( @havefood, 1)
  #NEWVAR stillhungry 0
} {
  #CR
  #SHOW <color cyan>I have no food in my %item( @havecontainer, @loopcount)!</color>
  #IF (@loopcount ~< @containercount) {
    checkcontainers
  } {
  #SHOW <color cyan>I have no food at all, better get some!</color>
  }
}]]></value>
    </alias>
    <var name="foodtypes" type="StringList">bread|apple</var>
    <var name="containertypes" type="StringList">backpack|pouch|bag</var>
    <var name="stillhungry">1</var>
    <var name="containercount">0</var>
    <var name="AlarmTime" type="String">2</var>
    <var name="havefood" type="String"/>
    <var name="havecontainer" type="StringList"/>
    <alias name="condel">
      <value>#DELITEM containertypes %1
#CR
#ECHO You have deleted %1 from your container list.</value>
    </alias>
    <alias name="eathelp">
      <value><![CDATA[#CR
#CR
#SHOW <color cornsilk><b>AutoEat Help</b></color>

#ECHO <color yellow>-----------------------------------------</color~>

#ECHO <color lightgreen>This script is to reduce the mundane eating crap!</color>

#ECHO <color lightgreen>Please set your AlarmTime Variable.</color>

#ECHO <color lightgreen>This variable is the delay time from the mud to</color>

#ECHO <color lightgreen>all of you things in your inventory and containter lists.</color>
#CR

#ECHO <color lightblue>salarm</color> <color yellow>-----</color><color red> Set the AlarmTime ~(variable). ex: salarm 3</color>

#SHOW <color lightblue>foodadd</color> <color yellow>-----</color> <color red>Add food to the food list ~(variable).</color>

#ECHO <color lightblue>fooddel</color> <color yellow>-----</color> <color red>Delete food from the food list ~(variable).</color>

#ECHO <color lightblue>conadd</color> <color yellow>-----</color> <color red>Add container to the container list ~(variable).</color>
#ECHO <color lightblue>condel</color> <color yellow>-----</color> <color red>Delete container from the container list ~(variable).</color>

#ECHO <color lightblue>eatshow</color> <color yellow>-----</color> <color red>Shows your list of food, containers and the AlarmTime ~(variables).</color>
#CR]]></value>
    </alias>
    <alias name="fooddel">
      <value><![CDATA[#DELITEM foodtypes %1
#CR
#IF ( @foodtypes ~= NULL ) {
#ECHO <color cyan>Invalid entry</color>
} {
#ECHO <color cyan>You have deleted %1 to your food list.</color>
}]]></value>
    </alias>
    <alias name="foodadd">
      <value>#ADDITEM foodtypes %1
#SORT foodtypes
#ECHO <color cyan>You have added %1 to your food list.</color></value>
    </alias>
    <alias name="salarm">
      <value>#var AlarmTime %1</value>
    </alias>
    <alias name="eatshow">
      <value><![CDATA[#CR
#CR
#ECHO <color yellow><b> *** YOUR LISTS ***</b></color>
#CR
#ECHO <color cornsilk><b>Food List</b></color>
#SHOW <color lightgreen><b>-----------------</b></color>
#LOOP 1,%numitems( @foodtypes) {
  #ECHO <color cyan> %i.</color> <color red>%item( @foodtypes, %i)</color>
}
#CR
#ECHO <color cornsilk><b>Container List</b></color>
#ECHO <color lightgreen><b>-----------------</b></color>
#LOOP 1,%numitems( @containertypes) {
  #ECHO <color cyan> %i.</color> <color red>%item( @containertypes, %i)</color>
}
#CR
#ECHO <color cornsilk><b>Alarm Time</b></color>
#ECHO <color lightgreen><b>-----------------</b></color>
#ECHO <color aqua>Your current alarm time is set to @bRed@AlarmTime@bCyan seconds.</color>
#CR]]></value>
    </alias>
    <alias name="conadd">
      <value>#ADDITEM containertypes %1
#SORT containertypes
#ECHO You have added %1 from your container list.</value>
    </alias>
    <trigger priority="250">
      <pattern>You are {hungry|really hungry.|feeling slightly hungry.|starving}</pattern>
      <value>#NOOP Clear the variables
#VAR havefood {}
#VAR havecontainer {}
#VAR loopcount 0
#VAR containercount 0
#VAR stillhungry 1
#NOOP Run your command to show your inventory
#echo The have container: @havecontainer
inventory</value>
      <trigger>
        <pattern>*</pattern>
        <value>#echo Enter First state
;#CLASS CheckItems 1
#T+ ConTypeTrig
#T+ FoodTypeTrig
#echo Exit First state</value>
      </trigger>
      <trigger type="Alarm">
        <pattern>@AlarmTime</pattern>
        <value><![CDATA[#T- ConTypeTrig
#T- FoodTypeTrig
#CLASS CheckItems 0
#echo In the AlarmType
#IF (%numitems( @havefood)~>0) {
#echo Inside the if
  eat %item( @havefood, 1)
  #AB 1
} {
  #CR
  #SHOW <color cyan>I have no food in my inventory list.</color>
}
#IF (%numitems( @havecontainer)~>0) {
  #VAR stillhungry 1
  #VAR containercount %numitems( @havecontainer)
  checkcontainers
} {
#CR
#SHOW <color cyan>I have no containers need go buy one, duh!</color>
}]]></value>
      </trigger>
    </trigger>
    <var name="loopcount">0</var>
  </class>
  <class name="System">
    <trigger priority="10870">
      <pattern>You fall asleep.</pattern>
      <value>#NOOP Change the pattern to the output line of your mud for the sleep command.
#T- AutoEatTrig</value>
    </trigger>
    <trigger priority="10880">
      <pattern>You open your eyes</pattern>
      <value>#NOOP Change the pattern to the output line of your mud for the wake command.
#T+ AutoEatTrig</value>
    </trigger>
  </class>
  <trigger name="FoodTypeTrig" priority="50" enabled="false">
    <pattern>{(@foodtypes)}</pattern>
    <value>#echo Hit foodtypes
#NOOP Check to see if you have the food listed
#IF %ismember( %1, @foodtypes}) {#VAR havefood %additem( %1, @havefood)}</value>
  </trigger>
  <trigger name="ConTypeTrig" priority="430" enabled="false">
    <pattern>{(@containertypes)}</pattern>
    <value>#echo Hit containertypes1.
;#NOOP Check to see if you have the container listed
#IF (%ismember(%1,@containertypes)) {
#ADDITEM havecontainer %1
}
#echo @havecontainer
;#IF %ismember( %1, @containertypes){
;#echo See: %1
;#ADDITEM  havecontainer %1

;#VAR havecontainer %addItem( %1, @havecontainer)
;}
;#echo You have: @havecontainer</value>
  </trigger>
</module>
</cmud>

_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Nov 05, 2007 6:56 pm   
 
I have completed converting this script!!! It is now available in the Shared Package Library. You can now remove this post.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Nov 05, 2007 7:01 pm   
 
Noice. We prefer to leave posts hanging around unless they're abusive or something, though - it's possible it might help someone in the future.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Nov 05, 2007 7:43 pm   
 
Noice??? You mean Nice. ;)
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Mon Nov 05, 2007 8:36 pm   
 
It was more than likely a typo but sometimes in the UK we do pronounce the word in a weird way which could be written like that.
_________________
Taz :)
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Nov 05, 2007 9:15 pm   
 
Yeah, I'm on a Fast Show trip at the moment :)
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Nov 05, 2007 9:41 pm   
 
Can someone here install the package and see if they see anything I could improve on?
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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