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


Joined: 15 Nov 2001
Posts: 9
Location: Finland

PostPosted: Fri Nov 30, 2001 4:22 am   

Graphic bars into numbers
 
I've been trying to make a trigger which would calculate a graphic bar into numeric value.
The bar is made up of 5 characters, @ = 10k, # = 1k, X = 100, x = 10 and . = 1.
An example bar would be like this: [@@######XXXx.....] (26315 in numbers)
Problem is, that every character is not always present, which causes my trigger not to match the string.

The pattern I'm using is '~[([@])([#])([X])([x])([.])~]' and the trigger itself is '#mat dev ((%len( %1) * 10000) + (%len( %2) * 1000) + (%len( %3) * 100) + (%len( %4) * 10) + (%len( %5)))'

Is there any way to make it work using only a single (perhaps even simple) trigger?
And is it possible to make it use #sub command or similar to simply append the calculated value after the string itself?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Nov 30, 2001 7:41 am   
 
quote:

I've been trying to make a trigger which would calculate a graphic bar into numeric value.
The bar is made up of 5 characters, @ = 10k, # = 1k, X = 100, x = 10 and . = 1.
An example bar would be like this: [@@######XXXx.....] (26315 in numbers)
Problem is, that every character is not always present, which causes my trigger not to match the string.

The pattern I'm using is '~[([@])([#])([X])([x])([.])~]' and the trigger itself is '#mat dev ((%len( %1) * 10000) + (%len( %2) * 1000) + (%len( %3) * 100) + (%len( %4) * 10) + (%len( %5)))'

Is there any way to make it work using only a single (perhaps even simple) trigger?
And is it possible to make it use #sub command or similar to simply append the calculated value after the string itself?



This probably what your pattern should look like:

#FUNCTION Shift {%eval(%1,%2)}

#trigger {~[([~@~#Xx~.])~]} {#noop loop through each character in %1 and add to appropriate counter;#sub {~[%1 ~(@Shift(@TenThousands,10000)@Shift(@Thousands,1000)@Shift(@Hundreds,100)@Shift(@Tens,10)@Shift(@Ones,1)~)~]}}

dunno if the [] can be used inside the (), but I'll assume they can (for lack of a reason they aren't able to).

Stuff in red is where code needs to be written still (I'm too tired to work through the looping code, and if nobody else gets it up for you between now and early evening tomorrow I'll tackle it then).

li'l shmoe of Dragon's Gate MUD
Reply with quote
Acaila
Apprentice


Joined: 30 Aug 2001
Posts: 187
Location: Netherlands

PostPosted: Fri Nov 30, 2001 10:39 am   
 
Using Matt's pattern you can problably do it like this (untested!):

#VAR List {@=10000|#=1000|X=100|x=10|.=1}
#TRIGGER {~[([~@~#Xx~.])~]} {#LOOPDB @List {#ADD Value %val};#SUB {%1 (@Value)};Value = %null}

The variable @List contains the pattern with their corresponding values. The trigger adds all those values together and substitutes the line received from the mud.

Also, you might need to put a tilde in front of those patterns in the @List that can be parsed.

Acaila
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Fri Nov 30, 2001 11:42 pm   
 
quote:

Using Matt's pattern you can problably do it like this (untested!):

#VAR List {@=10000|#=1000|X=100|x=10|.=1}
#TRIGGER {~[([~@~#Xx~.])~]} {#LOOPDB @List {#ADD Value %val};#SUB {%1 (@Value)};Value = %null}

The variable @List contains the pattern with their corresponding values. The trigger adds all those values together and substitutes the line received from the mud.

Also, you might need to put a tilde in front of those patterns in the @List that can be parsed.

Acaila



I tried to do it like that first, but the X and the x cant both be together. (I tried to create it by entering it into the database var directly in the settings editor). When I clicked save, it decided that the little x was the same as the big X, and since you cant have to keys the same, deleted the second.

Caled
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Sat Dec 01, 2001 6:00 am   
 
This problem interested me, so I went out and worked on it.
I tested this and it appears to work perfectly.
I know you probably have one of the other suggestions working now,
but I did it cos it intrigued me, and I figured I might as well put it up here.



#CLASS {Graphbar}
#VAR symbols {"@"|"#"|"X"|"x"|"."}
#VAR values {"10000"|"1000"|"100"|"10"|"1"}
#FUNCTION symbolconv {%item( @values, %ismember( %1, @symbols))}
#TRIGGER {^~[([~@~#Xx~.])~]$} {graphbar=%1;graphbarval=0;#LOOP 1,%len( %1) { #ADD graphbarval @symbolconv( %copy( @graphbar, %i, 1))};#SHOW %ansi( 12)@graphbar --- @graphbarval}
#CLASS 0


The final value ends up in the variable: @graphbarval

Caled
Reply with quote
OggTheGorillaEmperor
Newbie


Joined: 15 Nov 2001
Posts: 9
Location: Finland

PostPosted: Sun Dec 02, 2001 3:21 am   
 
After testing I decided to use Caled's solution.
I had to modify the pattern a bit to avoid matching similar graph bars, but it seems to work perfectly.

Thanks to everyone for help.
Reply with quote
OggTheGorillaEmperor
Newbie


Joined: 15 Nov 2001
Posts: 9
Location: Finland

PostPosted: Sun Dec 02, 2001 5:19 am   
 
Now that I've been playing for a while, I came up with something weird.
Pattern [@@......] transforms into [@.]when ran thru the trigger (one that Caled posted.
I can't find anything that would cause this, what the hell?
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Sun Dec 02, 2001 7:50 am   
 
I did this:
#SAY ~[~@~@~@~.~.~]
And it equated to 20001, not 30002 like it should.

#say ~[@@@.~]
Equates to 30001, as it should.
#say ~[@@@..~]
Goes to 20001. I'd say its a bug.
#say ~[@@..~]
Goes to 10001
#say ~[@.~]
goes to 10001
#say ~[@..~]
goes to 1

The problem is that it doesn't like the period if there is more than 1.

Caled
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Sun Dec 02, 2001 7:55 am   
 
Here's some more stuff.

Have this in the command line.
grp={@@.}
#sh <@grp>

IT returns: @@.

grp={@@..}
#sh <@grp>

This returns: @.


Zugg???


Caled
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Dec 03, 2001 2:09 am   
 
You guys need to remember that @ is the variable expansion character in zMUD. Have you changed @ to something else in the special characters? Also, the dot (.) is used for array indexing, list indexing, and database variable fields.

If you want to assign a *string* to a variable, do this:

grp="@@."

stop using {}. The {} allows zMUD to parse the stuff inside, causing all sorts of trouble with the @ and . characters. The quotes forces zMUD to treat the stuff inside as a verbatim string. It's *very* important to get this right.

Also, drop the extra <> around stuff. You should almost never need to use <> or [] around stuff in a script. Just doing:

#SAY @varname

is fine.

Now, the problem you are having with "#SAY @grp" is that once again, the @ and . characters inside @grp are messing you up. zMUD *recusively* expands stuff. So, @grp expands to "@@.." and then zMUD tries to expand this (which is invalid syntax) and ends up with "@."

To force zMUD to only expand *once*, you can use the %expand function:

#SAY %expand(@grp,1)

will display "@@.." correctly since it is only expanded once.

Anyway, my main suggestion to this entire thread is that you pick characters different from @ and . In your original trigger, convert the @ . characters from the MUD into characters not used by zMUD. Then do your calculations based on these other characters. You will have a much easier time.

Something like:

#CLASS {Graphbar}
#VAR symbols {"a"|"#"|"X"|"x"|"b"}
#VAR values {"10000"|"1000"|"100"|"10"|"1"}
#FUNCTION symbolconv {%item( @values, %ismember( %1, @symbols))}
#TRIGGER {^~[([~@~#Xx~.])~]$} {
graphorig="%1"
graphbar=%replace(%expand(@graphorig,1),"@","a")
graphbar=%replace(%expand(@graphbar,1),".","b")
graphbarval=0
#LOOP 1,%len(@graphbar) {#ADD graphbarval @symbolconv(%copy(@graphbar,%i,1))}
#SHOW %ansi( 12)%expand(@graphorig,1) --- @graphbarval
}
#CLASS 0

Notice the " around %1 when assigning to graphorig to treat %1 as a pure string.
Notice the use of %expand everywhere there might be a @ or . character to prevent recusive expansion.
Notice the use of @graphbar in the %len of the loop statement which is ok since all of the special characters have been replaced.

Anyway, this problem and script is a great example of the care that must be taken when dealing with special characters. With special characters, getting the syntax *exactly* right and understanding exactly how zMUD parses text is very important.

Oh, and to test it, all you need is stuff like:

#SAY "[@@@..]"

Once again, use the quotes instead of going crazy with the ~ character.

For more info, see the "zMUD Programming Language" and the "Advanced zMUD Variables" articles in the Support Library. Even though the second article talks about stuff in v6.2x, a lot of the discussion about strings is still valid in order versions.

(Btw, Caled: Even though it seems the right thing to do, please avoid the <code> and </code> stuff. First, you can't copy/paste this text into zMUD to test it. Second, it causes the forum to make the entire topic as wide as your longest line, which annoys people. Just put your code in as regular forum text like I did.)


Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Mon Dec 03, 2001 3:26 am   
 
Zugg,
Firstly...okay. I will forget the [code] thing from now on.
And...just a little thing about the <> thingies I had in the script....they were there because I
was typing it direct into the command line, and its needed to force expansion there.

And lastly, thanks a heap for the wonderful reply....I learned a lot.


Caled
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Dec 03, 2001 7:22 am   
 
You still don't need the <>, not even on the command line. Expansion is determined by the arguments to the command you are using. The #SHOW command expands it's arguments, so the <> are not needed.

Reply with quote
cingulli
Wanderer


Joined: 30 Aug 2001
Posts: 53
Location: Finland

PostPosted: Mon Dec 03, 2001 12:49 pm   
 

lyriikka.tripod.com
has something similar to this for BatMUD

it works on lines likes these
e.g.
Reputation bar:
[@@@@###:]

needs a bit tweaking to suit for OggTheGorillaEmperor type bars, but it can count reputation lines like 70k pretty quickly. ,)
Reply with quote
Francezca
Beginner


Joined: 09 Nov 2001
Posts: 11
Location: New Zealand

PostPosted: Tue Dec 04, 2001 12:44 am   
 
Maybe you could just install the graphic plugin?

I am not sure what you are wanting your graphic to show but the plug-in
can be easily adapted to show whatever you like.

Frannie
Reply with quote
OggTheGorillaEmperor
Newbie


Joined: 15 Nov 2001
Posts: 9
Location: Finland

PostPosted: Wed Dec 05, 2001 3:34 am   
 
Now this is getting intresting. After corrections by Zugg, the trigger still gives wrong results...
Pattern [@@@XXxxxxxxxx...] gives value of 30000.
But if I add a # between @ and X, it gives the correct value of 31283.

And for Francezca, I've no use for graphics plug-in, I want numbers here, not graphics.

-Ogg
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Dec 05, 2001 9:29 am   
 
Make sure your trigger is set to "Case sensitive"

Reply with quote
OggTheGorillaEmperor
Newbie


Joined: 15 Nov 2001
Posts: 9
Location: Finland

PostPosted: Thu Dec 06, 2001 10:44 am   
 
It is now. Doesn't work any better.. in fact, [@@@XXXXXXxxx] sums up as 20000 now.
Then, if I add # after @'s, it gives the correct value.
But if a . is added after lower case x's, it gives 30000 again.

Have I missed something?

-Ogg
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Thu Dec 06, 2001 10:58 am   
 
Modify it so it changes all symbols to different letters.

Caled
Reply with quote
OggTheGorillaEmperor
Newbie


Joined: 15 Nov 2001
Posts: 9
Location: Finland

PostPosted: Thu Dec 06, 2001 11:46 am   
 
I made it that way right from Zugg's advise, there are only letters in the bar.

-Ogg
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Dec 06, 2001 3:03 pm   
 
Open the settings editor and look for the trigger. Make sure the pattern of the trigger appears like this:
^~[([@#Xx.])~]$

When I entered Zugg's script into zMUD it stripped all ~. Furthermore, in the range of the pattern [@#Xx.] Zugg used ~ before @ and #, but to make it work I had to remove them.

After correcting the pattern, doing:
#sh "[@@@XXxxxxxxxx...]"

returns:
@@@XXxxxxxxxx... --- 30283

which is the correct value.

Kjata
Reply with quote
OggTheGorillaEmperor
Newbie


Joined: 15 Nov 2001
Posts: 9
Location: Finland

PostPosted: Sun Dec 09, 2001 1:19 am   
 
Nope. It is correct. And it doesn't seem to matter whether there are tildes in the range of pattern or not. I tried both ways with same results.

#sh "[@@@XXxxxxxxxx...]" gives 30000
#sh "[@@@#XXxxxxxxxx...]" gives 31283
#sh "[@@@XXxxxxxxxx]" gives 20000

And I just don't get it.

-Ogg
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