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^2
Newbie


Joined: 22 Dec 2004
Posts: 2

PostPosted: Wed Dec 22, 2004 1:58 pm   

Strange behavior of zmud triggers and scripts
 
Some years ago I tried zMUD 5.xx in hope of finding a good client for windows. I some problems that I was unable to solve back then (I even asked around in old zMUD forums without a solution), so I gave up and stuck with TF. Now, I after starting to play again big more regularly, I decided to give it another go to see if things have improved.

Sadly, as much improvement has happened over years, I'm again experiencing strange behavior I can't get a grasp of and I've decided to look further into the matter.

Now, there is this "reputation bar" with certain characters representing different numerical values, like this:
Quote:

[@@@@@@@:::......]


It's just by itself on a line. The characters used are X (10000), @ (1000), # (100), : (10) and . (1).

And the thing I'm after is a trigger that would translate strings like this into numerical values so, that I can see if my own reputation has changed after last check even if I look up other people in between. Seems simple enough. First, there is a command that checks if the argument to the command that shows reputation is myself and sets a flag accordingly.

Then, there is the trigger itself cathing the line, using a regexp pattern:
Code:

^\[(X*)(\@*)(#*)(:*)(\.*)\]$


Works just as expected. Then comes the trigger script:
Code:

#if (@BarbRepSelf=1) {#var BarbRepOld @BarbRep}
#var BarbRep %eval( %len( %1)*10000+%len( %2)*1000+%len( %3)*100+%len( %4)*10+%len( %5))


Nothing unexpected at this point, if the command is used on self, old reputation from variable BarbRepOld and the numerical value from the string in BarbRep

Now, I wanted to append this value after the original string. So I at first I tried to create a variable containing the triggered patterns and the value using function concatenate:
Code:

#var BarbRepString %concat( "[", %1%2%3%4%5, "] [", @BarbRep, "]")


Perfect, now I have just the thing I needed in the variable BarbRepString:
Quote:

[@@@@@@@:::......] [7036]


All I need is to substitute the triggering line with the contents of this variable:
Code:

#sub @BarbRepString


Oops, something didn't go right. The line shows now only the number:
Quote:

7036

Perhaps if I try with %eval:
Code:

#sub %eval(@BarbRepString)


Still the line contains just the number, this time without the spacebar in front:
Quote:

7036


At this point I decided that perhaps using the variable was not a good idea to begin with, so I thought of a different approach. I'll just use the substitute command without the variable in between:
Code:

#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"] ["%eval(@BarbRep-@BarbRepOld)"]"


Quote:

[@@@@@@@:::......] [7036] [0]


Now it worked just the way I wanted it, I even added the change from previous check and some highlight. But I wanted it to show only when I checked my own reputation, so I changed it a bit:
Code:

#if (@BarbRepSelf=1) {#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"] ["%eval(@BarbRep-@BarbRepOld)"]"} {#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"]"}


Ok, now I see the change only when checking my own reputation.. but what is this:
Quote:

[@@@@@@@:::......] [7036] 0


What happened to the square brackets around the change bit? Strange, lets experiment a bit:
Code:

#if (@BarbRepSelf=1) {#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"] $"%eval(@BarbRep-@BarbRepOld)"$"} {#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"]"}

And we get:
Quote:

[@@@@@@@:::......] [7036] $0$

Just like it should. So it should work. Therefore, I'll just change the dollar signs to square brackets like before:
Code:

#if (@BarbRepSelf=1) {#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"] ["%eval(@BarbRep-@BarbRepOld)"]"} {#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"]"}


And still, no square brackets:
Quote:

[@@@@@@@:::......] [7036] 0


After experimenting a while, almost any characters in place of square brackets show, even if I just remove one from either side, the other shows. Very funny.


Is there a logical explanation to this? This is not the first time in a week I've had problems with strange results, just the first time I've been unable to think of a kludge to circumvent it.


And the trigger script entirely at this point:
Code:

#if (@BarbRepSelf=1) {#var BarbRepOld @BarbRep}
#var BarbRep %eval( %len( %1)*10000+%len( %2)*1000+%len( %3)*100+%len( %4)*10+%len( %5))
#if (@BarbRepSelf=1) {#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"] ["%eval(@BarbRep-@BarbRepOld)"]"} {#sub "["%1%2%3%4%5"] "%ansi(bold,white)"["@BarbRep"]"}
#if (@BarbRepSelf=0) {#var BarbRep @BarbRepOld}
#var BarbRepSelf 0


Sorry about the sucky formatting..
Reply with quote
misterbalrog
Apprentice


Joined: 26 Oct 2004
Posts: 108

PostPosted: Wed Dec 22, 2004 6:24 pm   
 
It has to do with the fact that brackets, [ ], are used to evaluate a mathematical expression within. Thus, if you either turn them off in the settings, or use tilde (~) preceeding them, you should be fine in printing them out. =)

That should solve it. =)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Dec 23, 2004 10:23 am   
 
You should also use braces around your #SUB arguement to make sure you only have 1 parameter.
#if (@BarbRepSelf=1) {#sub {~[%1%2%3%4%5~] %ansi(bold,white)~[@BarbRep~] ~[%eval(@BarbRep-@BarbRepOld)~]}} {#sub {~[%1%2%3%4%5~] %ansi(bold,white)~[@BarbRep~]}}

I recommend turning both "Use [] for evalution" and "Use <> for expansion" in the Script Parser preferences. These shortcuts often get in the way. While they are useful from the command line to reduce typing; I find that the frequency with which I would use them there is less then the problems they cause in scripts that have to proccess those characters.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
OggTheGorillaEmperor^2
Newbie


Joined: 22 Dec 2004
Posts: 2

PostPosted: Thu Dec 23, 2004 5:27 pm   
 
Thanks to both. That would explain it.. I never even thought about it since it works in two other parts. And I had them in parenthesis too.

I tried to use escape character at one point, but I forgot it was a tilde instead of backslash.. I suppose that's what you get for getting used to other environments and don't pay enough attention to one you are trying currently Embarassed
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