One question about text. [SOLVED]

This forum is currently in read-only mode.
From the Asset Store
Animated Text
$3.99 USD
With AnimatedText behavior you can make an impression of the text being “typed live”.
  • Is there a way to recognize only a part of a word and change the text?

    Example: I want to add the plural of Fairy. Can i make something like: If "y" is at the end of the word, delete it and add ies?

    Thanks for the help.

  • I'm not sure if I can help with reference to Constuct, but in my general experience with programming, you can normally do that with variables and arrays if i'm not mistaken.

  • I haven't used text too extensively, but it sounds like you might need an array for that. Store each letter separately and then check the last position for a y, that shouldn't be too difficult. But then again, I haven't used arrays either.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Maybe this would help? just press the plural button to change the text.

    http://dl.dropbox.com/u/7658043/plural.cap

  • Maybe this would help? just press the plural button to change the text.

    http://dl.dropbox.com/u/7658043/plural.cap

    I need to change all the words ending with y to plural.

    I haven't used text too extensively, but it sounds like you might need an array for that. Store each letter separately and then check the last position for a y, that shouldn't be too difficult. But then again, I haven't used arrays either.

    I don't know how to use array, someone can help me?

  • Replacing isn't that difficult. The system expressions "Get right substring", "Get left substring" and "Get string length" will help you with it.

    As a first exercise do this: Create a text box and create a private variable with the name word, the type text and the initial value fairy.

    In the event sheet insert a "start of layout"-event. Create a sub-event using System - Compare.

    In the first field enter right(Text.Value('word'), 1), comparison equal to, the second field should be "y".

    Now create an action to this condition. Set the text of the text box to left(Text.Value('word'), len(Text.Value('word')) - 1) & "ies"

    + System: right(Text.Value('word'), 1) Equal to "y"
    -> Text: Set text to left(Text.Value('word'), len(Text.Value('word')) - 1) & "ies"
    [/code:uzzt57u4]
    
    What is going on here is that you check if the last letter of the variable [i]word[/i] equals "y". right(text, count) returns the rightmost count letters of word. right("fairy", 1) returns "y", right("fairy", 2) would return "ry", etc.
    In our case the condition becomes true and the action is performed. Here we retrieve the leftmost letters of [i]word[/i]. left("fairy", 1) would return "f", left("fairy", 2) returns "fa", etc. We just need to know the length of the word to get rid of the "y". len(Text.Value('word')) returns the number of letters in [i]word[/i]. We just need to substract 1 from the length ("y" is just one letter). Now [i]left(Text.Value('word'), len(Text.Value('word')) - 1)[/i] returns "fair" and we just need to add our new ending. "fair" & "ies" concatenates to "fairies".
    Success!   
    
    You will most likely work with text, not just words. So you need to find a way to seperate the words of the text first and then use the above method. You will see that [i]GetToken(String, Index, Separator)[/i] is very helpful for that. For example, GetToken("I see fairy", 3, " ") will return "fairy", which you then could correct to "fairies", while rebuilding the text in a new variable or text box or whatever suits your needs.
  • Thank you very much!

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