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
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Mon Apr 12, 2010 7:01 pm   

Odd formatting issue
 
EDIT: Functions weren't working because they required some variables. They should work now. However, a much better scripter than I found a simpler way to show the issue, which is the code below.

Code:

#loop 15 {#SAY %format(&-20s,%concat(%ansi(%i),blah))%i}



To test, put in these two functions:

Code:

<func name="clancolor" id="501">
  <value>#RETURN %switch($char_clan = "Justice", 1, $char_clan = "Bloodlust", 4, $char_clan = "Knighthood", 9, $char_clan = "Shadow", 8, $char_clan = "Slayers", 14, $char_clan = "Conclave", 14, $char_clan = "Red Robes", 12, $char_clan = "Black Robes", 8, $char_clan = "White Robes", 15, $char_clan = "Shalonesti", 2, $char_clan = "Wargar", 11, $char_clan = "Loner", 15, $char_clan = "Renegade", 15, $char_clan = "Dragon", 10, $char_clan = "Angel", 10, $char_clan = "Demon", 10, $char_clan = "Retired", 15, %ismember($char_clan, @_kingdom_list), 3)</value>
  <arglist>$char_clan</arglist>
</func>

Code:

<func name="formatclan" id="526">
  <value>#IF ($_color) {
  $_c_color = @clancolor( $_clan)
  #SWITCH (%ismember( $_clan, @_clan_list)) {#RETURN "[ "%ansi( $_c_color)$_clan%ansi( reset)" ]"}
   ($_clan="Shalonesti-k") {#RETURN %ansi( 11)"("%ansi( 3)Shalonesti%ansi( 11)")"%ansi( reset)}
   (%ismember( $_clan, @_kingdom_list)) {#RETURN %ansi( 11)"("%ansi( 3)$_clan%ansi( 11)")"%ansi( reset)}
   (%ismember( $_clan, @_remort_list)) {#RETURN "( "%ansi( $_c_color)$_clan%ansi( reset)" )"}
   ($_clan="Retired") {#RETURN %ansi( 3)"("%ansi( $_c_color)$_clan%ansi( 3)")"%ansi( reset)}
  }
  {#SWITCH (%ismember( $_clan, @_clan_list)) {#RETURN "[ "$_clan" ]"}
   ($_clan="Shalonesti-k") {#RETURN "(Shalonesti)"}
   (%ismember( $_clan, @_kingdom_list)) {#RETURN "("$_clan")"}
   (%ismember( $_clan, @_remort_list)) {#RETURN "( "$_clan" )"}
   ($_clan="Retired") {#RETURN "("$_clan")"}}</value>
  <arglist>$_clan, $_color</arglist>
</func>


These variables
Code:

<var name="_clan_list" type="StringList" id="510">Wargar|Shalonesti|Conclave|Slayers|Red Robes|Black Robes|White Robes|Justice|Bloodlust|Shadow|Knighthood|Renegade|Loner</var>
 <var name="_kingdom_list" type="StringList" id="509">Althainia|Arkane|Verminasia|Darkonin|Shalonesti-k|Thaxanos|Arkane|New Thalos|Ganth|Marauders|Abaddon|Nordmaar|Gray Church</var>
<var name="_remort_list" type="StringList" id="511">Angel|Dragon|Demon|Giant|Balanx</var>


Then input this into the command line:
Quote:

#show %format(&-44 s,@formatclan("White Robes", 1)) Something
#show %format(&-44 s,@formatclan("Black Robes", 1)) Something
#show %format(&-44 s,@formatclan("Red Robes", 1)) Something
#show %format(&-44 s,@formatclan("Justice", 1)) Something
#show %format(&-44 s,@formatclan("Wargar", 1)) Something
#show %format(&-44 s,@formatclan("Shadow", 1)) Something


After that, go to the first function, find Shadow, and change the 8 that follows it to a 7. Then enter the quoted text into the command line again.

Why is this happening? I don't know of any logical reason as to why using 7 should produce different formatting than 8. I will say that the only difference between 7 and any other numbers is that 7 is the default color for my CMUD, so %ansi(reset) goes to 7, but I still don't see how that would affect formatting.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Apr 13, 2010 6:03 pm   
 
Curious, definitely looks like a bug.

I tried putting a %len() around that %format() statement, and every line came out as 20. But the display of the seventh line from your loop is clearly off.

My test was in v.3.16b.
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Apr 13, 2010 9:15 pm   
 
Not sure why this is happening yet either.

But the first argument of %format is a string and needs " quotes:

#show %format("&-44 s",@formatclan("White Robes", 1)) Something

otherwise the parser might not be passing the correct value to %format. Of course, this would effect all lines and wouldn't care if using 7 or 8.

You might try changing your default color to see if that has any effect.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Apr 14, 2010 5:09 am   
 
I tried changing the default color, and the new default color retains the effect. My friend thinks it has to do with how CMUD handles the colors, here's what he said:

MSN convo wrote:

(1:06:14 AM) Drax: I believe it's including the ansi color codes in the length of the string. So %e[a;bm where a and b are numbers that control the color and formatting of text (blinking, underlined, italics etc)
(1:06:46 AM) Drax: Your default color has a shorter code than the others, so it's getting more padding with white space.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Apr 14, 2010 4:29 pm   
 
Yes, I think your friend is correct. If it is using the ANSI reset string (ESC[0m) to set your default color, the it's definitely a shorter escape sequence and will get padded differently. The %format command will treat the control codes in the ANSI color as normal characters.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Apr 15, 2010 1:21 pm   
 
Hmm, and there's no way to change that?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Apr 15, 2010 3:51 pm   
 
Nope, sorry. The %format command is a system library utility (within Delphi) and not my own code. You might be able to write your own padding function that uses the %stripansi routine to remove the color codes to determine the "real" length of the string and then %concat the appropriate number of spaces using the %repeat function to generate a string of space characters of the correct length.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Apr 15, 2010 4:02 pm   
 
Yeah, that's my other plan. I had actually had a padding function until my friend told me about %format and I was like "This is great!" but, it's not perfect. I deleted the padding function, so I'll have to recreate it, but it's not terribly difficult. I had been using a loop before too, so it should be more efficient with %repeat. Thanks.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Apr 15, 2010 4:56 pm   
 
You might be better off using some prepatory logic to form the format-string used in %format(). If you put your coloring in this string instead of the data going into the placeholders, %format() won't have problems with the processing of ansi and other codes.
_________________
EDIT: I didn't like my old signature
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Apr 15, 2010 9:44 pm   
 
Not sure I understand what you mean, Matt.

The string in question uses a specific function which builds it from information given to it. Specifically, it is designed to look exactly like Clan and Kingdom flags appear in the game, color and all. The format is:
[ Clan ]
(Kingdom)

With some exceptions for remorts and a few other minor things. However, since the only colored portion of the flag is between the brackets, the only thing I can do is to color it beforehand.

Previously I had used logic to determine if it needed brackets or parenthesis. However, the exceptions plus other coloring things made the subsequent #show statements extremely long and difficult to read and alter. In favor of having cleaner scripting, I decided to encapsulate all of it in a variable which went into the #show statement. This means I lose the power that comes from adding extra elements after the color, but I gain things which I find more important for me.

Additionally, since I consider all parts of the flag to be part of the entire string, I need to include the brackets and parenthesis in order to account for their total length. True, I could use logic in the #show to once again determine that, but it makes it very long and unwieldy once more.

That's why I chose the method I did. I just made the padding function and it seems to be working perfectly. However, if I misunderstood your comment, then I would be interesting in hearing more about it so that I can have more efficient scripting, that's the ultimate goal. The most efficient scripts I can have that retain the functionality that I'm looking for.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Fri Apr 16, 2010 12:33 am   
 
Gosh that sounded complicated.

Try this:
Quote:
#FUNCTION jus($field, $string) {#IF %isnumber( $field) {$padding=%repeat( " ",%eval( %abs( $field)-%len( %stripansi( $string))));#IF $field<0 {#RETURN %concat( $string, $padding)} {#RETURN %concat( $padding, $string)}} {#RETURN $string}}


Then use @jus(f, s) to justify things much as you would use %format(a, b). In this function f is a number that controls the size of the field you want the string to occupy and s is your string. If f is a positive number the string will be justified to the right. If f is a negative number, the string will be justified to the left. If the string is longer than the intended field, or the first argument is invalid, string s will be returned unaltered. This function isn't as powerful or robust as %format() but should do everything you need it to, since you're not fiddling around with floating point variables and scientific notation.

Quote:
#LOOP 15 {#SAY @jus(-20,%concat(%ansi(%i),blah))%i}

It's essentially Zugg's solution.


Last edited by DraxDrax on Fri Apr 16, 2010 12:55 am; edited 2 times in total
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Apr 16, 2010 12:53 am   
 
Or you could just use a #CW trigger to color it after using the %format
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Apr 16, 2010 3:53 am   
 
%format("<color yellow>&2.0f</color> [&30s]",(14 - @black.ticks)

The bold part is what I mean, put the coloring outside of the placeholder and it doesn't affect the formatting of the placeholder.
_________________
EDIT: I didn't like my old signature
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Fri Apr 16, 2010 8:04 pm   
 
DraxDrax is the one that figured out why it wasn't formatting properly, by the way. He knows his stuff.
_________________
Listen to my Guitar - If you like it, listen to more
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