English Finding a String Size

6 replies
Goto Page
To the start Previous 1 Next To the start
26.11.17 08:20:49 pm
Up
Masea
Super User
Offline Off
Hello,

You know there is a
string.len
which returns how many characters in the string.

I want something similar to that. That will return the size of the string in x position.

Like,
Code:
1
2
3
str = "Hey."

print(string.leng(str))

This will show me 4. But the thing is, the dot takes less space than other characters. Just example, let's say "." takes 1 pixel, "H" 4, "e" 3 and "y" 3. But I'll never have an idea what exactly space do they take.

How to get these?
edited 1×, last 10.12.17 05:51:42 pm
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (27)
26.11.17 08:51:25 pm
Up
Gaios
Security Supporter
Offline Off
Impossible

You have to write own wrapper for that.
26.11.17 10:26:52 pm
Up
Infinite Rain
Reviewer
Offline Off
@user Gaios:
Yes, it is possible. You just have to write your own wrapper.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
26.11.17 10:27:51 pm
Up
gotya2
GAME BANNED
Offline Off
Just call this function on your string and you're golden.

https://en.wikibooks.org/wiki/BlitzMax/Modules/Graphics/Max2D#TextWidth

Now calling that function is a little bit more tricky within lua, but not impossible.
26.11.17 10:33:06 pm
Up
Infinite Rain
Reviewer
Offline Off
@user gotya2:
Go on...
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
27.11.17 07:02:40 am
Up
VADemon
User
Offline Off
@user Masea: Text size will depend on font used. Unless it's a standalone mod it will be unrealiable.
27.11.17 07:35:58 am
Up
Devil-Thanh
GAME BANNED
Offline Off
use your own image font instead of the game fonts, then write your own wrapper
To the start Previous 1 Next To the start