About Spritefont

For questions about using Classic.

Post » Mon Dec 13, 2010 5:56 am

hey

first of all, thanks for the autor for this plugin, it's very nice ;)

now the question.. can I limit the number of letters in the spritefont?
or if better, can I limit the number of letters before a dot?
like if limit is 4 before a dot and 2 letters after one it would be:
4420.40 or 30.63, etc..
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Mon Dec 13, 2010 11:45 am

Your question has actually nothing to do with spritefont, but with expressions you can use to manipulate strings, values and floats.

First I wanted to mention the FormatDecimal expression to you, but then I realized you wanted to manipulate the number of characters before and after the dot, maybe even with letters and not only numbers like in your example.

So you'll need Gettoken, it's a system expression. Take a look here:

[size=150:v4z25vm6]SYSTEM EXPRESSIONS[/size:v4z25vm6]

About the most important stuff to know about Construct. :)

So lets say you have a string "dadadudu.muhaha" and want to limit it to 4 characters before the dot and 2 characters after:

left(Gettoken("dadadudu.muhaha",1,"."),4)&"."&left(Gettoken("dadadudu.muhaha",2,"."),2)

Gettoken can take your string apart by using a delimiter character. In this example it's obviously ".". So when you write Gettoken("dadadudu.muhaha",1,"."), it will return the first token, which would be "dadadudu". Now this is enclosed in a left expression, which returns the defined number of characters from the left. Left("dadadudu",4) gives you "dada".

So by getting the two tokens, limiting them to the wanted amount of characters and putting a dot in between, you get the string you want. In case you need to understand more about these expressions just use the link above. Like I said, it's essential to know about the system expressions!
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Mon Dec 13, 2010 3:48 pm

Thanks, really helped ;)
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Dec 14, 2010 1:38 am

hey, doesn't gettoken works with private variables?
like
left(Gettoken(SpriteFont.Value('sdfsdf'),2,"."),1)

??
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Dec 14, 2010 9:06 pm

[quote="Guif0DA":1wkw9ysq]hey, doesn't gettoken works with private variables?
like
left(Gettoken(SpriteFont.Value('sdfsdf'),2,"."),1)

??[/quote:1wkw9ysq]
any1?
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Dec 14, 2010 9:15 pm

[quote:2fkul0qb]hey, doesn't gettoken works with private variables?
like
left(Gettoken(SpriteFont.Value('sdfsdf'),2,"."),1)

??[/quote:2fkul0qb]
If 'sdfsdf' is a string then it should work. But if it's a number then it needs to be converted into a string with the str() function.

left(Gettoken(str(SpriteFont.Value('sdfsdf')),2,"."),1)
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue Dec 14, 2010 9:29 pm

[quote="R0J0hound":1d3eswhl][quote:1d3eswhl]hey, doesn't gettoken works with private variables?
like
left(Gettoken(SpriteFont.Value('sdfsdf'),2,"."),1)

??[/quote:1d3eswhl]
If 'sdfsdf' is a string then it should work. But if it's a number then it needs to be converted into a string with the str() function.

left(Gettoken(str(SpriteFont.Value('sdfsdf')),2,"."),1)[/quote:1d3eswhl]
im not sure but i think I tryed using str() before posting.....but I'll see here again ;)
maybe forgot something
thanks for reply
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Tue Dec 14, 2010 11:06 pm

really workd!
i guess i used val() instead of str()
B
30
S
6
G
5
Posts: 433
Reputation: 6,061


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests