#(LG_Legacy) Text width and centering text

26 messages · Page 1 of 1 (latest)

peak gale
#

I've been trying to write a procedure that will center text within a specified textwidth but I'm having trouble with some spacing, which may of been present in some of my examples provided earlier.

There seems to be an extra space or two and I think I'm just doing my math or script wrong, I'd like a helpers opinion on how to do this, or if a script already exists like this where it accommodates for max width input then I would like to be directed there instead of re-inventing the wheel.

https://paste.denizenscript.com/View/112205 - Relevant debug
https://paste.denizenscript.com/View/112206 - Relevant script

crude bronzeBOT
#

(LG_Legacy) Text width and centering text

crude bronzeBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>

peak gale
#

Hm it seems like both examples didn't show up.

#

When not using the custom procedure for spacing to show that it's a problem with my procedure script.

peak gale
#

Oh you know what I see the problem.

#

I'm stopping the repeat after I've already added the character to the list.

#

And not before whilechecking if the text width including a new character is more than the maximum width.

#

If there is a more better way of doing this then I'm open to suggestions.

junior dagger
#

your original example looks exactly centered, the bar i added on the left and right is the exact same length

#

also yeah there is probably a better way.. if you have a resource pack you can use spacing characters to do it with a single tag before and after the text

#

which has the added benefit of letting you do single-pixel and even half-pixel precision

#

or if you really want spaces, there's pad_left and pad_right

#

for either method, it's just math. (max width - title width) / 2 is the width you need to add to each side

#

or, well the width you just need to pad to the left. considering you have a bar for the right width

peak gale
#

I don't want clients to rely on a resource pack, so this is the viable solution in terms of characters.

#

I have a resource pack and it's going to be soft-required, but I don't want full reliance.

#

Also I forgot about pad left and pad right lol.

#

Good stuff.