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
dazed-n-confused999
Wanderer


Joined: 03 Aug 2004
Posts: 79

PostPosted: Sun Mar 23, 2008 9:56 pm   

adding a constant to a list
 
when I look at my herb pouch I get this:

The pouch is well-made from quality leather, and has a number of separate pockets within which various herbs and poisons may be kept
separate. The pouch contains two hundred batches of Lestagii, two hundred batches of Yarl, two hundred batches of Breldiar, one hundred
and ninety-nine batches of Akmar, one hundred and ninety-nine batches of Nann, two hundred batches of Resik. It belongs to you.

I'm trying to create a list that displays the following:
200 Lestagii
200 Yarl
200 Breldiar
and so on...

Currently I'm using a trigger like this:
Pattern - two hundred batchs of (%w)
Value - @tempherb = %1 ; #additem pouchherbs @tempherb

This works ok to get the list of all the pockets containing 200 herbs. My main problems seems to be when I try to insert the number. I tried to do #additem pouchherbs 200 @tempherb, but to no avail. How do I get the number in front of the name in the list?

I'm not too concerned with accuracy, as long as the count is within 10 herbs I'm happy. So I've implemented a system like this:
one hundred and ninety(*)batches of (%w)
one hundred and eighty(*)batches of (%w)
and so on...
only snag I ran into was when the numbers get into the teens and units. ie.
one hundred and nineteen(*)batches of (%w)
one hundred and nine(*)batches of (%w)

Any sugestions of an easier way to deal with this other than making 20 seperate triggers to deal with each case? Only need accuracy to plus or minus 10 herbs.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Mar 24, 2008 1:10 am   
 
That's a bit of a pants way of doing it. Better would be something like

#trig {The pouch contains (*).} {PouchHerbs="";#forall %replace(%1,", ","|") {#addkey PouchHerbs %word(%i,2," of ") %word(%i,1," of ")}

This creates a data record variable, which is much more suited to this kind of data storage.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
dazed-n-confused999
Wanderer


Joined: 03 Aug 2004
Posts: 79

PostPosted: Mon Mar 24, 2008 1:41 am   
 
I tried to cut n paste that, but it gave me errors. I've never used the #addkey command so I'm not too sure what went wrong
Reply with quote
dazed-n-confused999
Wanderer


Joined: 03 Aug 2004
Posts: 79

PostPosted: Mon Mar 24, 2008 3:20 am   
 
RE: #trig {The pouch contains (*).} {PouchHerbs="";#forall %replace(%1,", ","|") {#addkey PouchHerbs %word(%i,2," of ") %word(%i,1," of ")}

After removing the period in the pattern and adding an ending braces I'm getting limited success.
Using my mudd output example I would only get "Lestagii two hundred batches" mapped to the database.
It seems to stop at the first parenthesis, any idea why?
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Mon Mar 24, 2008 4:34 am   
 
Okay, I'm an idiot. I forgot to mention that you'll need a words-to-numbers function on the second half. Viji has one for CMUD; I'm sure you can find one for zMUD in the Finished Scripts forum.

I'm afraid I don't have zMUD on my laptop so I can't debug that right now. My guess is that there's a linebreak just after the lestagii in the list - my resolution lined up just right that it looked like there weren't any linebreaks in your example. That'll require some more complex triggers, something like:

#trig {The pouch contains (*)} {PouchHerbs="";PouchCap=%1}
#cond {(*)} {#if (%pos(".",%1)) {PouchHerbs=%concat(@PouchCap,%word(%1,1,"."));#forall %replace(@PouchCap,", ","|") {#addkey PouchHerbs %word(%i,2," of ") @WordsToNums(%word(%i,1," of "))};#state 0} {PouchCap=%concat(@PouchCap,%1)}} {looplines|param=15}
#cond {} {#say "Pouch cap has been active for 15 lines! Oh dear, something's gone wrong :("}

Assuming that your pouch won't ever be 15 lines long. @WordsToNums is a function like I described above.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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