having XyText Centered
|
Gattz Gilman
Banned from RealLife :/
Join date: 29 Feb 2004
Posts: 316
|
02-24-2005 23:43
i got 5 XyText prims, but i want the text thats going to show up to be in the middle of all of them.
I have an idea oh how:
the string to be sent to the XyText = text
llGetStringLength(text)
then from there i know how many spaces to add infront of it. But the things is, how would i do "ex: 3 * 'space' + text"?
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
02-24-2005 23:56
string msg = "Xytext is Old Skool"; integer number_characters = 40; integer number_spaces = (number_characters - llGetStringLength(msg)) / 2;
integer i; for(i = 0; i < number_spaces; i++) msg = " " + msg; Cheap, but effective.
_____________________
---
|
Kyrah Abattoir
cruelty delight
Join date: 4 Jun 2004
Posts: 2,786
|
02-24-2005 23:58
string func_center_text(string text,integer char_per_line) { string blanks = (char_per_line - llStringLength(text))/2; integer i; for (i=0;i < blanks;i++) text = " " + text; return text; }
jeff already replied i know but i was writing it in my editor, so i still post it  i like functions 
_____________________
 tired of XStreetSL? try those! apez http://tinyurl.com/yfm9d5b metalife http://tinyurl.com/yzm3yvw metaverse exchange http://tinyurl.com/yzh7j4a slapt http://tinyurl.com/yfqah9u
|
Gattz Gilman
Banned from RealLife :/
Join date: 29 Feb 2004
Posts: 316
|
02-25-2005 00:02
Awesome, TYVVVVM
|
Gattz Gilman
Banned from RealLife :/
Join date: 29 Feb 2004
Posts: 316
|
02-25-2005 00:08
ok...i feel really stupid, but, how exactly would i implement it? so, would i do?: string msg = "Xytext is Old Skool"; integer number_characters = 40; integer number_spaces = (number_characters - llGetStringLength(msg)) / 2;
integer i; for(i = 0; i < number_spaces; i++) { msg = " " + msg; } llMessageLinked(LINK_SET,1,msg,"");
?? Sorry, but its 3am here hehe, brain tired
|
Kyrah Abattoir
cruelty delight
Join date: 4 Jun 2004
Posts: 2,786
|
02-25-2005 00:11
if unsure use my function, paste it at the very top of your script then when you want to center a text type :
func_center_text("XYTEXT RULES",40); it will return the text centered on 40 charcters
so you can do
strin myoutput = func_center_text("XYTEXT RULES",40);
_____________________
 tired of XStreetSL? try those! apez http://tinyurl.com/yfm9d5b metalife http://tinyurl.com/yzm3yvw metaverse exchange http://tinyurl.com/yzh7j4a slapt http://tinyurl.com/yfqah9u
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
02-25-2005 07:52
In your case, you have 5 XyText Prims, so that's roughly 30 characters (2 chars times three faces times five prims). string msg = "Xytext is Old Skool"; // Edit this to accept whatever message you wish integer number_characters = 30; // 30 Chars integer number_spaces = (number_characters - llGetStringLength(msg)) / 2; // Leave me alone
integer i; for(i = 0; i < number_spaces; i++) msg = " " + msg; This is rough code that'll return the proportional number of spaces you want, in addition to the actual message. Then you just stick that string into XyText. 
_____________________
---
|
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
|
02-25-2005 09:02
integer display_len = 30; integer padding_len = (display_len - llGetStringLength( msg )) / 2; msg = llGetSubString( " ", 0, padding_len ) + msg;
A little faster than a for loop to build the text. There are 16 spaces between the quotes.
_____________________
~ Tiger Crossing ~ (Nonsanity)
|
Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
|
02-25-2005 13:55
nice lateral thinking Tiger 
|