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
rhodesroach
Newbie


Joined: 01 Apr 2007
Posts: 7

PostPosted: Sat Apr 07, 2007 6:20 am   

counting items without the container being listed in the same line
 
Ok I am attempting to count candles that are lit on a workbench let me show you.

A black oak workbench.
On it you see:
a tallow pillar candle (lit), a tallow pillar candle (lit), a tallow pillar
candle (lit), a tallow pillar candle (lit), a tallow pillar candle (lit), a
tallow pillar candle (lit), a tallow pillar candle (lit), a tallow pillar candle
(lit), a tallow pillar candle (lit), a tallow pillar candle (lit), a tallow
pillar candle (lit), a tallow pillar candle (lit), a tallow pillar candle (lit),
a tallow pillar candle (lit), a tallow pillar candle (lit), a tallow pillar
candle (lit), a tallow pillar candle (lit), and a tallow pillar candle (lit).

Now i have looked through the forums and found stuff similar but how would i go about counting these candles when i try to add to a variable it only adds one per line.
When I tried some of the codes I found on here it didn't work because the container description is on a different line. So how does it work so that i know how many candles are on this darn thing?

Thanks,
Rhodesroach
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Sat Apr 07, 2007 9:13 am   
 
By far the easiest way would be to set your line width to 0 and turn off server-side word wrapping. If you can do that it'll make this (and many other things) much easier.

If that's not an option, the easiest way is to compile a single string variable, remove the separators, and use %numwords to count the number of apostrophe-delimited phrases. Roughly:

#var Contents ""
#var NumItems ""
#trig {On it you see:} {#var Contents "";#var NumItems "";#t+ ContentsDetect}
#trig "ContentsDetect" {(*)} {#additem Contents %1;#if (%ends(%1,".") {#t- ContentsDetect;#var NumItems %numwords(%replace(@Contents,"|"," "),",")}}
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
rhodesroach
Newbie


Joined: 01 Apr 2007
Posts: 7

PostPosted: Sat Apr 07, 2007 4:56 pm   an easier way?
 
ok I tried that and I guess I don't understand enough about it so it didn't work right. Isn't there an easier method for this. Is there a way for example for everytime the word "lit" shows up in a line to activeta the trigger and add one to the variable? I made this work with a really old version of Zmud now that I have a new comp and lost it all I am having to start over. How do I make the trigger recognize that one word multiple times in a line? If I can make it recognize it multiple times in the same line and activate the trigger then it would just add to the variable for each time it sees that word instead of for each line it see's the word.
Thanks,
Rhodesroach
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Apr 07, 2007 6:57 pm   
 
Triggers only fire once per line, so just triggering on the word "lit" won't work.
_________________
EDIT: I didn't like my old signature
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Tue Apr 10, 2007 8:38 am   
 
Code:

#VAR regstring {}
#VAR count {}
#TRIGGER {~(lit~)} {#var regstring "%0";#add count %mss(%concat("x=",%string(@regstring).match(/\(lit\)/g),";if(x!=null)x.length;else 0"),"JScript")}


If you don't mind making the trip to JScript, this works;
Using the regular expression /\(lit\)/g and the String Object's match function to find each occurrence of (lit) in the line that activates the trigger.
The trailing 'g' of the regular expression is necessary as explained here on this msdn help page. The with the g global operator set the match function returns an array for each match and returns null if no match is found.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Tue Apr 10, 2007 12:01 pm   
 
Damn I found another, easier solution :p
Anyways here it is
Code:

#VAR count {}
#TRIGGER {~(lit~)} {#add count %eval( %numwords( " %0", "~(lit~)") - 1)}

That's it! numwords used this way will return 1 more than the correct amount, unless the first argument is a null string so we have to subtract 1.
In this case it returns 0, since %0 wont be an empty string that wont be a prob, also we led with an extra space so it surely wont be a prob.
not what it was meant for but it works, and its simple.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
rhodesroach
Newbie


Joined: 01 Apr 2007
Posts: 7

PostPosted: Tue Apr 10, 2007 4:22 pm   Thankyou
 
Woho!!!!
It did work thankyou. I set up an alias to set the var to 0 first then look at the item and then echo it to me and it worked perfect.. Thankyou Thankyou Thankyou.. I knew there had to be an easy way to do it..
Thanks,
Rhodesroach
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