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


Joined: 22 Aug 2003
Posts: 12
Location: United Kingdom

PostPosted: Sat Jan 31, 2004 8:33 pm   

Maths and data lists
 
Ages ago I was having trouble with the reparse command and asked on here for help.

I want to trigger on, say pouch #12 has 12 batches of wirren, 2 batches of harfy, 5 batches of wirren.

So I would end up with a list saying 2 harfy and 17 wirren

#forall %replace( "%1", ", ", "|") {#if ("%i" =~ "(%d) batches of ({wirren|jegga|harfy})") {#if (%iskey( %%2, @Herbs)) {#addkey Herbs %%2 %eval( %db( @Herbs, %%2) + %%1)} {#addkey Herbs %%2 %%1}}}
#loopdb @Herbs {#echo %val %key}

The above was posted on here, and I tried to use it, at the time I had no clue what to do with it in terms of actually creating a data record variable (I was really green, and still am) then I stopped playing the mud for a while.

I've since came back, and decided to try it again, I've got it owrking in that it will put some numbers into the list, and i'm expanding it to inlude other herbs and stuff, but

a)it looks like you can't do maths with data records, and
b)I don't really understand what the above is doing

if I wanted to actually make it ADD the numbers together I think i'd need to do something like take the number in the herbs list, put it into a variable, add the new number, then put it back in, but I can't see how to do that....

I know the logic behind what I want to do, but I don't get the syntax or what's happening here.

I don't want it all written FOR me as I'd like to learn, but any pointers would be much appreciated.

--
Etali
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sat Jan 31, 2004 9:35 pm   
 
Ok then lets start at the beggining, Explaine waht it is you want exactly to do with:

#12 has 12 batches of wirren, 2 batches of harfy, 5 batches of wirren.

So I would end up with a list saying 2 harfy and 17 wirren
do you just want it to tell you:
num 12 has the following: 2 harfy and 17 wirren

or do you want to store it in the database
or is it that someone made this with a database variable and that is what you want to use.

You see there is actually different ways to do this and they will all get the job done.

[qoute]I want to trigger on, say pouch #12 has 12 batches of wirren, 2 batches of harfy, 5 batches of wirren.[/qoute]
I am starting on something now that will actually tach you how to do something like this so tell me if I am wrong.
Reply with quote
etali
Beginner


Joined: 22 Aug 2003
Posts: 12
Location: United Kingdom

PostPosted: Sat Jan 31, 2004 10:28 pm   
 
I have several pouches so I want it to total across ALL pouches, then display a list at the end of:

12 wirren
5 jegga
99 harfy

Or whatever, after triggering on several of those pouch #99 contains... lines

The variable of that type was something I chose, I think. And I'm happy to have them in a list like that.

I might save the list to a text file or something, but I haven't decided yet.

Thanks in advance :>

--
Etali
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Sat Jan 31, 2004 11:00 pm   
 
Mud Output! nuff said :P
Reply with quote
etali
Beginner


Joined: 22 Aug 2003
Posts: 12
Location: United Kingdom

PostPosted: Sun Feb 01, 2004 12:00 am   
 
I don't understand what you mean there?
Reply with quote
etali
Beginner


Joined: 22 Aug 2003
Posts: 12
Location: United Kingdom

PostPosted: Sun Feb 01, 2004 3:00 am   
 
Ok, I'm not going to be defeated by this, but I'm confused.

I've been reading up on various stuff and apparently %eval forces and expression to be evaluated.

In the code I gave above, I was assuming that all it did was overwrite whatever was already stored for that herb or poison in the data table.

So... what does {#addkey Herbs %%2 %eval(%db(@Herbs,%%2) + %%1)} do?

It LOOKS like it adds the (%d) batches of to whatever is already stored there, but it doesn't seem to be doing that when I run it?

Thanks everyone for advice and patience :>

--
Etali
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sun Feb 01, 2004 11:19 am   
 
Here you go I will explan this sometime soon to tired right now, works well on the example you gave

Copy and past everything between the lines to your command line then hit enter.
___________________________________________________________________

#CLASS {Couting}
#VAR Ct {}
#VAR Ct2 {}
#VAR CtNu {}
#VAR CtNa {}
#VAR CtNaT {}
#VAR CtNuT {}
#VAR CtN1 {}
#VAR CtN2 {}
#TRIGGER {^#(%d) has (*)} {Ct="";Ct2="";CtNu="";CtNa="";CtNaT="";CtNuT="";#var Ct %replace(%replace("%2",", ","|"),".","");#loop 1,%numitems(@Ct) {#var Ct2 %additem(%replace(%item(@ct,%i)," batches of ","|"),@Ct2)};#loop 1,%numitems(@Ct2) {#var CtNu %additem(%item(%item(@Ct2,%i),1),@CtNu);#var CtNa %additem(%item(%item(@Ct2,%i),2),@CtNa)};#loop 1,%numitems(@CtNa) {#if %ismember(%item(@CtNa,%i),@CtNaT) {#var CtN1 %item(@CtNu,%i);#var CtN2 %item(@CtNuT,%ismember(%item(@CtNa,%i),@CtNaT));#var CtNuT %replaceitem(%abs(@CtN1+@CtN2),%ismember(%item(@CtNa,%i),@CtNaT),@CtNuT)} {#var CtNaT %additem(%item(@CtNa,%i),@CtNaT);#var CtNuT %additem(%item(@CtNu,%i),@CtNuT)}};#loop 1,%numitems(@CtNaT) {#echo %item(@CtNaT,%i) %item(@CtNuT,%i)}}
#CLASS 0

______________________________________________________________________
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sun Feb 01, 2004 11:21 am   
 
oh yeah I did not take out the @herbs and stuff but if you give me some better prompts and thing you want out I will help, like I said I will explain more when I get some rest.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Feb 01, 2004 8:42 pm   
 
When asking questions about a trigger, please include the PATTERN of the trigger. It makes it much easier to understand, especially when the trigger uses %1 or other numbered parameters which refer to the pattern.

The problem is fairly basic. You have the order of parameters reversed in the %iskey function.

Going back to the original trigger, which I found easily with the Search link (keywords wirren jegga harfy):
#TR {pouch ~#%d contains (*).} {#FORALL %replace( "%1", ", ", "|") {#IF ("%i" =~ "(%d) batches of ({wirren|jegga|harfy})") {#IF (%iskey( @Herbs, %%2)) {#ADDKEY Herbs %%2 %eval( %db( @Herbs, %%2) + %%1)} {#ADDKEY Herbs %%2 %%1}}};#LOOPDB @Herbs {#SHOW %val %key}}
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Mon Feb 02, 2004 7:36 am   
 
I said I would explain
quote:

a)it looks like you can't do maths with data records


You can but it takes practice.

I have found that when writing a script like this it helps to first start with what I got, then Write what I whant the go about it step by step:

In the above example you had this:
pouch #12 has 12 batches of wirren, 2 batches of harfy, 5 batches of wirren.

Then you said you wanted this:
So I would end up with a list saying 2 harfy and 17 wirren

Ok so first thing first you have to get that info captured into a variable so you can play with it, A trigger would work best.

#trigger {#12 has 12 batches of wirren, 2 batches of harfy, 5 batches of wirren.} {#var Ct "batches of wirren, 2 batches of harfy, 5 batches of wirren"}

But this will only work on the above example and is not flexiable enogh so we have to consider that everything after "#12 has " changes
and probably the 12 too, we also want to not reconize the # as Part of zmud programming.

#trigger {~#(%d) has (*)} {#var Ct "%1"}
now you get this in the var when it triggers
12 batches of wirren, 2 batches of harfy, 5 batches of wirren.

I usually use a show to make sure it works like so:
#trigger {~#(%d) has (*)} {#var Ct "%1";#show @Ct}
This way I can keep track of my progress and make sure I am not missing anything.

Next you need to seperate and remove all unwated text
#var Ct %replace(@Ct,", ","|")
using this in the last trigger will show you this:
12 batches of wirren|2 batches of harfy|5 batches of wirren.
nesting replace's is a great way of getting rid of stuff and save room, but can be a bit much to keep trak of as shown:
#var Ct %replace(%replace(@ct,", ","|"),".","")
will stripout the formentioned stuff plus the .
You can always write these steps seperatly then nest them.
%replace(@ct,", ","|") = gives you seperate items
%replace(@ct,".","") = removes the .
%replace(@ct," batches of ","") =replaces batches of with nothing

%replace(%replace(@ct,".",""),", ","|")
%replace(%replace(%replace(@ct," batches of ",""),".",""),", ","|")
using cut and past over the @ct each time, but be carful as to placement because it could chang the meaning in some circumstances.

Thats enough for now Got to get some rest.
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