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


Joined: 23 Jul 2004
Posts: 3

PostPosted: Fri Jul 23, 2004 11:58 pm   

Prompt Modifier
 
Someone gave me this code so long ago I forgot who it was. Although it does what I want it do zMud gives it a sytax error. The code modifies my prompt so that it displays my max of health, mana, and moves, plus it gives different colors when I am low on health and an incredibly annoying sound to make sure I pay attention. It uses my score output to update the maxes as far as I know. Also this allows the prompt to track and update other parts of the script, mainly for hunting and avoiding.

First I have zMud version 7.05
Here is what the mud displays normally:

<232hp 368m 275mv>

Now here is the erroneous code, I would greatly appreciate it if anyone could see what is done wrong perhaps it is affecting me and I just don't realize it. Thankyou in advance! Now here it is:

hp = %1;m = %2;mv = %3;#MATH dhp @maxhp*25/100;#MATH dm @maxm*25/100;#MATH dmv @maxmv*25/100;#IF ((@dhp>=@hp) and (@alarm=0)) {#IF @sounds {#PLAY warning.wav}};#IF (@dhp<@hp) {alarm=0} {alarm=1};#MATH checkstats (%len(%left(@primary,1))+%len(%left(@secondary,1))+%len(%left(@shield,1))+%len(%left(@held,1)));#SUBSTITUTE %ansi(9)(%ansi(%if(@dhp>=@hp,12,cyan))%1%ansi(9)/%ansi(%if(@dhp>=@hp,12,cyan))@maxhp%ansi(9)hp %ansi(%if(@dm>=@m,12,cyan))%2%ansi(9)/%ansi(%if(@dm>=@m,12,cyan))@maxm%ansi(9)m %ansi(%if(@dmv>=@mv,12,cyan))%3%ansi(9)/%ansi(%if(@dmv>=@mv,12,cyan))@maxmv%ansi(9)"mv")%if(@checkstats>2,%ansi(12)" **FIX YOUR STATS**",);#IF @mirrorscheck {mirrorshere=@mirrorsheretemp;mirrorsheretemp=0;mirrorscheck=0} {#ADD mirrorshere @mirrorsheretemp;mirrorsheretemp=0};#IF ((@sneakflee) AND (@track="yes")) {scan all} {#IF ((@ihavefled) AND (@fleeback)) {scan all}};sneakflee=0;ihavefled=0
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Jul 24, 2004 2:54 pm   
 
The code looks to be very solid. I would suggest 2 small changes.
"#IF @mirrorscheck {" should be "#IF (@mirrorscheck) {"
'#SUBSTITUTE %ansi(9)....' should be '#SUBSTITUTE {%ansi(9)....}'
Neither change really seems necessary; they are more meant for clarity. zMud uses 2 different parsing methods on scripts. One is slow and thorough, it is used for the syntax checker. The other is fast and used to actually preform the script. The syntax checker occasionally sees things it doesn't like, but they are perfectly fine. Such errors in the syntax checker are generally low priority bugs.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Sat Jul 24, 2004 3:23 pm   
 
Playing with this code, it's just giving a syntax error because there's a space in front of %ansi, which isn't really a syntax error (it's an error in the syntax checker), and so far as I can tell, it should work well.

My suggestion to make it look a lot nicer, and easier to track errors is to create a function to determine the colors:
Quote:
#FUNC PromptColor {%if(%1<%2,%ansi(cyan),%ansi(12))%1%ansi(9)/%if((%1<%2,%ansi(cyan),%ansi(12))%3%ansi(9)}

Then, in your prompt trigger, use the following substitute:
Quote:
#SUB @PromptColor(%1,@dhp,@maxhp)hp @PromptColor(%2,@dm,@maxm)m @PromptColor(%3,@dmv,@maxmv)mv
_________________
.geniusclown
Reply with quote
shanomi
Newbie


Joined: 23 Jul 2004
Posts: 3

PostPosted: Sat Jul 24, 2004 5:00 pm   
 
Awesome, thankyou Vijilante those two fixes made the syntax checker go away and put it in all pretty print which makes it easier for me to understand and try to learn from. Since I didn't write this I was always puzzled how this worked and working through that whole mess usually got me more confused, seeing as the help files aren't very detailed. Also, I noticed the part that I squiggly-braketed right after #SUBSTITUTE, is not in the pretty print wasn't sure if that is how inherit functions display or not:

{%ansi(9)(%ansi(%if(@dhp>=@hp,12,cyan))%1%ansi(9)/%ansi(%if(@dhp>=@hp,12,cyan))@maxhp%ansi(9)hp %ansi(%if(@dm>=@m,12,cyan))%2%ansi(9)/%ansi(%if(@dm>=@m,12,cyan))@maxm%ansi(9)m %ansi(%if(@dmv>=@mv,12,cyan))%3%ansi(9)/%ansi(%if(@dmv>=@mv,12,cyan))@maxmv%ansi(9)"mv")%if(@checkstats>2,%ansi(12)" **FIX YOUR STATS**",)}

geniusclown, the code you wrote, is that for a new trigger altogether that seperately marks the colors inside the script or does it add on to the already existing trigger. I am not very familiar with the way %ansi works or most % functions. So be gentle in your explaination Wink .

Thankyou
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Sat Jul 24, 2004 7:59 pm   
 
When you run across a new function or command, it's always a good idea to look it up in zMUD's help docs, which are wonderfully detailed and well cross-referenced.

You know that commands execute stuff, and always start with a #. Functions can occur just about anywhere within commands, and rather than doing something, it outputs something. You can think of functions as being variables (starting with @), but instead of being static (whatever's stored in them), their values depend on the input. Compare these two scenarios, one using #IF command, the other using %if function, both producing identical output:
Quote:
#ALIAS Testit {
#IF (%1="true") {#VAR TestVariable {is}} {#VAR TestVariable {isn't}}
#SH {The first parameter @TestVariable "true".}
}

Quote:
#ALIAS Testit {#SH {The first parameter %if(%1="true","is","isn't") "true".}

In my suggestion earlier, I said you should use the #FUNCTION command, which creates a variable that acts like a function. So, the following scenario will produce the same as above, but using a custom function.
Quote:
#FUNC Testing {%if(%1="true","is","isn't")}
#ALIAS Testit {#SH {The first parameter @Testing(%1) "true".}

So, my earlier suggestion doesn't create a trigger that colors when zMUD sees the prompt, but rather creates a function that colors your prompt within the #SUBSTITUTE command before (while?) it's sent to the output window.

I hope this is helpful.
_________________
.geniusclown
Reply with quote
shanomi
Newbie


Joined: 23 Jul 2004
Posts: 3

PostPosted: Sun Jul 25, 2004 10:37 am   
 
Ah ok that helped a lot more than the help file did, I learn by examples best, sometimes exclusively.

There is a little discrepancy with the suggestion for improving my prompt cause as is it makes the colors based on a comparison between two unrelated variables, namely my hp and my mana but I believe I can work on it and fix it myself. Get some practice in as well to make this stick. Thankyou both so much again.
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