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
RobAMacAF
Beginner


Joined: 24 Nov 2005
Posts: 19

PostPosted: Mon Mar 22, 2010 5:20 pm   

Arrays and Triggers - Need help
 
I am trying to make it that when I type inventory it will save all of my items into an Array.

When I type inventory I get...
You are wearing a branch-framed canvas backpack, a homespun green wool cap, some faded pants, and a patched rawhide workcoat.

I'm trying to use something like:

#TRIGGER (You are wearing) {
#COND (* &inv,* &inv2, * &inv3.) {
#VAR arrayCount %arrhigh(inventory)
#CALL %arrset(inventory,@arrayCount+1,@inv1)
#CALL %arrset(inventory,@arrayCount+1,@inv2)
#CALL %arrset(inventory,@arrayCount+1,@inv3)
}
}

That isn't the real code. It's close but I wasn't sure how to type it all here. Anyway. It would work. If I was wearing ONLY three things. I want to make it so it's flexible. If I am wearing one, it adds one. If I am wearing two, it adds two, etc.

Any ideas?

Thanks
Rob
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Mar 22, 2010 5:42 pm   
 
Well, first recommendation: don't use an array. That is a misuse of arrays. Arrays are intended for COM functions. Use a stringlist instead. Stringlists are much easier to use.

The following trigger should do most of what you want:
Code:
<trigger priority="10" id="1">
  <pattern>You are wearing (*).</pattern>
  <value>myinventory = %replace(%replace(%1,", and ","|"),", ","|")</value>
</trigger>

It will replace ", " or ", and " with a pipe character, "|", which is a symbol used to separate values in a stringlist. Do your item names ever have a comma within the name, such as "a large, brown, rectangular box"? If they do, we will have to use a slightly more complex replacement, but it would still not be hard.
Reply with quote
RobAMacAF
Beginner


Joined: 24 Nov 2005
Posts: 19

PostPosted: Mon Mar 22, 2010 5:44 pm   
 
I didn't think of using it like that! Thank you! While I was waiting for a reply I thought maybe I could use LUA to code it instead of zscript. I got lua to capture the whole line then I was going to use string.match to break it apart into the individual pieces. I ran into a problem though because I couldn't figure out if lua variables are saved inbetween runs and if not, how do I convert a lua variable into a cmud one.
Reply with quote
RobAMacAF
Beginner


Joined: 24 Nov 2005
Posts: 19

PostPosted: Mon Mar 22, 2010 5:58 pm   
 
I am playing around with what Rahab told me. It is capturing the whole item name like: a long dark cloak and the next item: a awesome looking sword....etc

I am now trying to make it that it only captures the LAST word of each one. Or using FORALL and changing each one real quick in a loop so
a long dark cloak becomes cloak
an awesome looking sword becomes sword

But I'm stuck again!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Mar 22, 2010 6:14 pm   
 
You may run into two problems that Rahab didn't handle (the list looks like a Dragonrealms list). The first is the loss of the comma in a 2-item list. The replace would never see that particular and because the replace is looking for a comma. The second would be complex or detailed items that incorporate the word and into their description (ie, a medallion of stars and stripes). The replace would divide "medallion of stars and stripes" into "medallion of stars" and "stripes". This can be further complicated with the use of proper participles (a, an, some) that one might try to use to separate items more accurately.
_________________
EDIT: I didn't like my old signature
Reply with quote
RobAMacAF
Beginner


Joined: 24 Nov 2005
Posts: 19

PostPosted: Mon Mar 22, 2010 8:21 pm   
 
MattLofton wrote:
You may run into two problems that Rahab didn't handle (the list looks like a Dragonrealms list). The first is the loss of the comma in a 2-item list. The replace would never see that particular and because the replace is looking for a comma. The second would be complex or detailed items that incorporate the word and into their description (ie, a medallion of stars and stripes). The replace would divide "medallion of stars and stripes" into "medallion of stars" and "stripes". This can be further complicated with the use of proper participles (a, an, some) that one might try to use to separate items more accurately.



Thanks for that advice. I did end up thinking about that and I don't have a problem with it. This is just a general appraisal script so if it even gets a list of 70% of what I'm wearing. Then that is ok.

I am still trying to figure out how to cut down the saved terms
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Mar 22, 2010 8:46 pm   
 
Actually, my replace specifically only replaced " and " if it was preceded by a comma, but you're right about not catching cases where there is no comma separating a pair of items.
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