About Spritefont

This forum is currently in read-only mode.
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • 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..

  • 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:

    SYSTEM EXPRESSIONS

    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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks, really helped

  • hey, doesn't gettoken works with private variables?

    like

    left(Gettoken(SpriteFont.Value('sdfsdf'),2,"."),1)

    ??

  • hey, doesn't gettoken works with private variables?

    like

    left(Gettoken(SpriteFont.Value('sdfsdf'),2,"."),1)

    ??

    any1?

  • [quote:2fkul0qb]hey, doesn't gettoken works with private variables?

    like

    left(Gettoken(SpriteFont.Value('sdfsdf'),2,"."),1)

    ??

    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]hey, doesn't gettoken works with private variables?

    like

    left(Gettoken(SpriteFont.Value('sdfsdf'),2,"."),1)

    ??

    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)

    im not sure but i think I tryed using str() before posting.....but I'll see here again

    maybe forgot something

    thanks for reply

  • really workd!

    i guess i used val() instead of str()

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)