How do I count and get characters in text?

0 favourites
  • 3 posts
From the Asset Store
An educational game for counting pictures. An easy to use template for developers to build larger games
  • Hey guys! Can someone help me please? I want to count and get characters in text based on buttons. Below what i need:

    Example:

    1 Text:
    HELLO
    BYE
    
    3 Buttons[/code:11d5bsz2]
    
    [b]Button 1 (Count lines)[/b]:
    Answer: In this example need to appear "2". We have 2 lines in text.
    
    [b]Button 2 (Count characters)[/b]:
    Answer: In this example need to appear "5" for the first line and "3" for the second line.
    
    [b]Button 3 (Get a character from line)[/b]:
    Answer: If for example i choose from the first line (HELLO) the second character, the result need to be the letter "E".
    
    [h2]Can someone help me please? Thanks![/h2]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From the System Expressions page of the C2 manual:

    len(text) [can be used to do your button 2]

    Return the number of characters in text.

    mid(text, index, count) [can be used to do your button 3]

    Return the count characters starting from index in text.

    For button 1, you could separate your lines with a special character and then use that as a marker to split each line into tokens and count the tokens. For example you could format it as "HELLO\BYE" and do this: tokencount("HELLO\BYE", "\")

    https://www.scirra.com/manual/126/system-expressions

  • Thanks for your help my friend!

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