Highlight part of a word (string) in Condition

0 favourites
From the Asset Store
Word Guess
$10 USD
Questions and answers are stored in simple txt-files. Cool animation of everything
  • Hi,

    Is it possible to do the following from the below event:

    If textinput1.text="word" > perform action

    My aim is to highlight the 'or' and perform an action based on whether this is true or not. So I need it as a condition.

    Is this possible?

    Many thanks.

  • What do you mean by "highlight"?

    If you want to test if a string contains substring 'or', you need to use find() expression:

    System Compare two values -> find(textinput1.text, "or") greater or equal 0 : perform action

  • Hi,

    So basically I want to check if a player is using a curse word as part of his name at the start of the game. I have a text box where he enters his game name. I know how to highlight entire words such as "curse1" but not words that are hidden in the middle of words, like "Name1Curse1Name2".

    I'd like to bring up a message if "Curse1" is hidden in the middle of a name like above.


    In Textinput1 check to see if entered text contains the word or string "Curse1"


    Textbox1 shows message - word is not permitted.

  • In this case you need to use find() expression, see my previous comment.

  • Shoukdn't the comparison be 'equal to'.....'1' - perform action

    its nor working for some reason

  • No, find() returns the position of substring if found, or -1 (minus 1) if not found. That's why you check if it's equal or greater than 0.

    find("abcdef", "abc") will return 0

    find("abcdef", "cd") will return 2

    find("abcdef", "xyz") will return -1

  • Thanks it works now :)

    Instead of typing in the letters to be checked, is it possible to add an array in the field? So that all words in a single array can be checked against the text box entry?

  • Yes, you can do something like this:

    Set variable badWordFound to 0
    Array For each element X
     Find(Textbox.text, Array.CurValue)>=0 Set badWordFound to 1
  • Seems to be working but only if I have 1 entry in the array.

    If I add multiple the textbox shows up empty each time, sometimes shows the last entry I made....not sure why.

    I might just use your first example.

  • It would be much easier to help you if you post screenshots of your code.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Again, your mistake is that you are executing everything on every tick!

    Create a button that submits the text and move these events into "On button clicked":

    Also, make sure that all cells in the array contain data. If any cell is empty, then find() expression will return 0. Or add another condition - Array.CurValue not equal ""

  • But if I don't have a second condition to check if a word 'does not exist' how can I change the textbox back to empty (not showing the 'not allowed' message)?

  • Just try my code and you'll see that it works. Note that the variable is local (defined inside the event). It gets reset to 0 every time the event is executed.

  • dop2000 you are a genius.

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