TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

@center function

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Finished Scripts
View previous topic :: View next topic  
Author Message
dorian



Joined: 29 Jul 2012
Posts: 66

PostPosted: Tue Sep 06, 2016 8:13 am    Post subject: @center function Reply with quote

someone may need this :

Code:

#function center {
   #var {_text_} {%1};
   #var {_len} {%2};
   #var {_length} {%2};
   #format len {%L} {$_text_};
   #if {$len < $_len} {
      #math {_len} {(($_len-$len)/2)};
      #math {_post} {$_len+$len};
      #format {result} {%+${_post}s} {$_text_};
      #format {result} {%-${_length}s} {$result};
   };
   #else {
      #format result {%.${_length}s} {$_text_};   
   };
   #return $result;
}


centers your text to given length ie: @center{test;10}, returns { test }
Back to top
View user's profile Send private message
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Mon Sep 12, 2016 5:45 pm    Post subject: Reply with quote

At least it does for ASCII text - may not be so good on Utf-8 text streams, IMHO.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Mon Sep 12, 2016 7:41 pm    Post subject: Reply with quote

#format %L should handle UTF-8 correctly if config chatset UTF-8 is enabled. Though tintin assumes all UTF-8 characters are one character wide.
Back to top
View user's profile Send private message Send e-mail
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Mon Sep 12, 2016 8:41 pm    Post subject: Reply with quote

Scandum wrote:
...Though tintin assumes all UTF-8 characters are one character wide.
Yeah, and there is not an easy way around that that I can see,,, Nope
Back to top
View user's profile Send private message
abedour



Joined: 29 Oct 2010
Posts: 37

PostPosted: Fri Feb 24, 2017 8:27 am    Post subject: Reply with quote

Just want to alternatively show a function which creates a right/left effect (right aligns the first argument, left aligns the second argument as normal).

Code:
#function {ralign}
{
#format {a} {%C};
        #format {d} {%L} {%2};
        #format {j} {%L} {%1};
        #math {e} {$d+$j};
        #math {e} {$a-$e};
        #format {b} {%s%s%s} {%%+} {$e} {s};
        #var g {};
        #format {c} {$b} {$g};
        #format {h} {%s%s} {$c} {%1};
        #format {f} {%s%s} {%2} {$h};
        #return $f
}
Back to top
View user's profile Send private message
ixle



Joined: 15 Sep 2011
Posts: 158
Location: United States

PostPosted: Fri May 26, 2017 7:04 am    Post subject: Reply with quote

There was a change some time ago that required curly braces around variables with special characters, so I have updated the original code so that it functions properly again. Pretty nifty little function.

Code:
#function center {                                                                                                                                             
   #var {_text_} {%1};                                                                                                                                         
   #var {_len} {%2};                                                                                                                                           
   #var {_length} {%2};                                                                                                                                         
   #format len {%L} {${_text_}};                                                                                                                               
   #if {$len < ${_len}} {                                                                                                                                       
      #math {_len} {((${_len}-$len)/2)};                                                                                                                       
      #math {_post} {${_len}+$len};                                                                                                                             
      #format {result} {%+${_post}s} {${_text_}};                                                                                                               
      #format {result} {%-${_length}s} {$result};                                                                                                               
   };                                                                                                                                                           
   #else {                                                                                                                                                     
      #format result {%.${_length}s} {$_text_};                                                                                                                 
   };                                                                                                                                                           
   #return $result;                                                                                                                                             
}     
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Finished Scripts All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group