How to compare just one word out of line of a TextObject

0 favourites
  • 9 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Hello there

    I would like to ask how I can compare just a part of a TextObject to use it in a condition of an event?

    I know that it's easy to compare the full text string of a TextObject (with 'compare text - condition of Text Object) put I can not find a way to compare just one word (so I can Use it when different strings are containing the same word)

    Thanks in advance


  • Hi,

    This will do.

    Use system expression mid(Text,Index,Length) to get what you need.


    Text - text you want to be checked.

    Index - where program should start from seeing the word. In our case we have to search for it with system expression find(Text,Find)

    Length - we use expression len to calculate length of text you want to be found so only this word would be shown. So in case of "MultikillGladiator" we will get "kill" , not "killGladiator"

    You can use it in actions too.

  • Thank you very much for your quick response and big help!!

    Just what I needed!

  • I thought it was working, but I was wrong.

    I've tested now in a simple event, but it doesn't work

    Any idea where the problem should be?

    Thanks anyway, I think you gave the right track, but maybe something is missing?

  • I think what you are looking for is the find() expression:

    Set variable S to "The quick brown fox jumps over the lazy dog"
    System-> Compare two values -> find(S, "fox")>=0   
    find() expression returns position of the string ("fox") inside another string (S). 
    It returns -1 if string was not found. So if the result >=0, this means that the string was found.
  • Hey Thank you very much for your response!

    I don't that will be the way. (Cause the system condition 'compare 2 values' does'nt pick objects.

    Let me explain the purpose more precisely:

    I have for example 10 different textlines in a php.file.

    One and the same text object is picking out 1 of those textlines randomly.

    For example: in three textlines there is the word "Shooter" like in "You got a new highscore in Shooter"

    Each time there is a textline with the word "Shooter" in, I would like to show a sprite next to the textobject.

    I want to make a condition just for textobject instances with that word, and not comparing text for each of the 3 sentences.

    Thanks for searching a solution with me!


  • I think you can still use "find". And if you want to pick TextObject with your event, do this:

    System -> Pick by comparison -> TextObject where find(TextObject.text, "Shooter")>=0

    This will pick all TextObjects which contain this word.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • haha, yes, now it works!!

    finally, what a relief

    A huge thank you for your time!

  • No problem, glad I was able to help!

    And it didn't take any time at all

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