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


Joined: 18 Dec 2003
Posts: 3

PostPosted: Thu Dec 18, 2003 3:34 pm   

Forcing fixed width of elements in lists
 
Greetings,


I am using triggers to capture values into a list, obtaining for example
this:

#VARIABLE list {|Name|Value1|Value2|%cr|James|assassin|321|%cr|Alexander|warrior|16}

which I display using #SAY %replace(@list,|," "), getting:
Code:

   Name   Value1   Value2   
   James   assassin   321   
   Alexander   warrior   16

But I would like to force it to take a set amount of characters for each
element (for example 12), in order to obtain neat columns:
Code:

   Name        Value1      Value2   
   James       assassin    321
   Alexander   warrior     16

Would anyone have an idea about how to do this?


Thank you for your attention,

Kharash the Noegyth.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Dec 18, 2003 5:29 pm   
 
Add spaces to each entry to make them the length that you prefer.
Reply with quote
Kharash
Newbie


Joined: 18 Dec 2003
Posts: 3

PostPosted: Thu Dec 18, 2003 6:08 pm   
 
Thank you for the input.
The problem was that those names were captured with triggers
using (%w) wildcarts. So I couldn't set the length. But this
seems to fix it:

#MATH temporary (13-%len(@name))
#WHILE (@list <> 0) {#VAR name {%concat(@name," ")};#ADD temporary -1}

Seems to work fine.
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Thu Dec 18, 2003 9:22 pm   
 
Check out the %format() for when you add elements into the list perhaps.

Probably better to use record types (%db() %addkey() etc)
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Dec 18, 2003 10:07 pm   
 
I'd use %1%repeat( " ", %eval( 13 - %len( %1))) with {} as delimiters. Faster than a loop.

I agree with Ton that a record-variable would be better than a list.
Reply with quote
Kharash
Newbie


Joined: 18 Dec 2003
Posts: 3

PostPosted: Fri Dec 19, 2003 8:22 am   
 
Thanks, I'll look into those. I went with a list because I won't have
more than ten names at most each time, and am not too familiar with the DB,
but I'll try it out.
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Fri Dec 19, 2003 9:05 am   
 
Here would be an idea; Someone more awake probably can drudge up something simpler Smile:

#VAR dbtest ""

Keep a index/counter of how many groups we have stored:
#ADDKEY dbtest counter=1

Loop this when groupings are added:
#ADDKEY dbtest {Name_@dbtest.counter=Name|Value1_@dbtest.counter=Value1|Value2_@dbtest.counter=Value2}
#ADD dbtest.counter 1

Loop again:
#ADDKEY dbtest {Name_@dbtest.counter=James|Value1_@dbtest.counter=assassin|Value2_@dbtest.counter=321}
#ADD dbtest.counter 1

Loop again:
#ADDKEY dbtest {Name_@dbtest.counter=Alexander|Value1_@dbtest.counter=Warrior|Value2_@dbtest.counter=16}
#ADD dbtest.counter 1

To see the results with %expanddb:
#SH %expanddb(@dbtest,%crlf,":")

To see something with some semblance of columns:
#LOOP @dbtest.counter {#SH %format("&10s",%db(@dbtest,Name_%i)) %format("&10s",%db(@dbtest,Value1_%i)) %db(@dbtest,Value2_%i)}
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