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


Joined: 26 May 2020
Posts: 10

PostPosted: Tue Jun 09, 2020 5:25 am   

Capturing quantities
 
Hi guys,

I have a situation where I am trying to store quantities of various herbs as variables, but I have the challenge of multiple ways to detect them...

So my variable for barberries is @invbarberries
But they can either show up as

a handful of barberries (this would be a single barberries)
a handful of barberries [14] (this would be 14 barberries which are not bundled)
a handful of barberries {4/20} (this means there are 4 in a bundle of potentially 20)

I think capturing the two different bracket types is easy enough, but capturing the single one... im not sure how to do, since it gets detected on those bundles and multiples.
Would verbatim on just the trigger for singles potentially grab that?

As a secondary thing, i wonder if you guys could think of a way to catch multiple copies of that herb... so if for example i had a single one, and a couple of bunches of varying amounts, could i catch all of that?

Right now I was just using &invbarberries in those two patterns with multiples... but I am actually wondering if maybe I shouldnt do something like invbarberries=@invbarberries+(however many there are)

Kind regards,
Miss Apathy
Reply with quote
MissApathy
Beginner


Joined: 26 May 2020
Posts: 10

PostPosted: Tue Jun 09, 2020 7:42 am   
 
Another thing I am trying to work out is how to take a bunch of variables and work out which one has the highest number.

If only the %max command let me know which actual variable was the biggest rather than just showing the number hehe.
Reply with quote
hpoonis2010
Adept


Joined: 18 Jun 2019
Posts: 279

PostPosted: Tue Jun 09, 2020 5:05 pm   
 
You could add them to an array/string list and perform a simple start to finish test.

I have a function doing just that:

max-val = func(@itemlist}

Code:
$max_val = %item($local_scores,1)

// Loop through each item in @var_scores comparing the previous value with the current value and assign if larger.
#LOOP 1,%numkeys($local_scores) {
  #IF (%item($local_scores,%i)>$max_val) {$max_val=%item($local_scores,%i)}
  }
 
// Return the NAME (key) of the highest value

#RETURN %dbkey($local_scores,%isvalue($local_scores,$max_val))
Reply with quote
chaossdragon
Apprentice


Joined: 09 Apr 2008
Posts: 167

PostPosted: Tue Jun 09, 2020 5:12 pm   
 
Is the "a handful of barberries" the only thing on the line (not counting the [#] and {#/##}) If so then I would use ...

Code:
#REG {^a handful of barberries$} {invbarberries = (@invarberries + 1)}
#REG {^a handful of barberries (?:\[(\d+)\]$|\{(\d+)\d+)$} {invbarberries = (@invarberries + %1)}


This covers the singlular as well as the pair of X value with minimal triggers.
I do something along these lines for the mud I play on that also deals with herb quanties.
Reply with quote
MissApathy
Beginner


Joined: 26 May 2020
Posts: 10

PostPosted: Tue Jun 09, 2020 10:07 pm   
 
Wow awesome work guys, thanks heaps this pretty much covers all of my scenarios.

I really appreciate this.
Reply with quote
MissApathy
Beginner


Joined: 26 May 2020
Posts: 10

PostPosted: Sun Jun 21, 2020 4:31 am   
 
Hey Hpoonis2010 how would I go about making an array from the existing variables?

Basically I have like invaloe = 2, invbarberries=20, invgarlic=10 etc
How would I go about getting those names and values into the array in a somewhat automatic way?
And I guess update the array somehow as well?

At the moment I have the neat regex stuff with a few tweaks (wasnt quite catching the {}), and that all works pretty reliably...
So I want to make a simple alias called HERBCHECK which will clear all the current variables to 0, check my bags to get accurate counts on them again, and then needs to find the one with the biggest value.
Could I make the array somehow inside that alias, and then have it run the function over it and automatically select the variable with the highest quantity?
Reply with quote
MissApathy
Beginner


Joined: 26 May 2020
Posts: 10

PostPosted: Sun Jun 21, 2020 5:46 am   
 
Actually I just got really lazy...and did this for every herb.... seems to work.

curelightherb=none
curelightcount=0
#IF (@invaloe>@curelightcount) {curelightcount=(@invaloe);curelightherb=aloe}
#IF (@invbarberries>@curelightcount) {curelightcount=(@invbarberries);curelightherb=barberries}
#IF (@invbasil>@curelightcount) {curelightcount=(@invbasil);curelightherb=basil}
#IF (@invcomfrey>@curelightcount) {curelightcount=(@invcomfrey);curelightherb=comfrey}
Reply with quote
chaossdragon
Apprentice


Joined: 09 Apr 2008
Posts: 167

PostPosted: Sun Jun 21, 2020 6:07 am   
 
In regards to the REGEX not properly capturing the {}'s

Code:
#REG {^a handful of barberries (?:\[(\d+)\]$|\{(\d+)\/\d+\})$} {invbarberries = (@invarberries + %1)}


I must have copied the wrong line when I tested it, my bad.
Reply with quote
hpoonis2010
Adept


Joined: 18 Jun 2019
Posts: 279

PostPosted: Wed Jul 15, 2020 12:29 pm   
 
@MissApathy

I currently have such a thing. I use it to populate a few buttons: HEAL, MANA, MOVE.

An alias for each. Eg., qhp. 'qhp' will remove all heal potions potions from a bag, and put them back again. In aard, if I take a few of same object then it displays something like "You take 27 <potion> from a bag of aardwolf" and "You put 43 <potion> into a bag of aardwolf"

<potion> being a variable. I exampled get and put with different numbers because, if I acquired more of the same then all items being held will go into the bag. From the entry figure I can populate the variable in the button with the correct amount. (However, I also decrement the figure every time I click the button and use a potion).

The point being, use a globally available variable for your herbs and, if your mud shows you some output for items in containers then it is simple to script a trigger to grab the number and populate a variable.
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