Quick question: 'contain' string

0 favourites
  • 2 posts
From the Asset Store
This collection of music is the beautiful performance of rather small strings ensemble (8 first violins, 6 second violin
  • Hello peoples.

    A quick question. I'm experimenting with a 'terminal game'. I want the game to compare what's in a text input box, but how do I get it so that Construct checks to see if what's in the input box contains a word.

    Here's an example:

    I want the Construct to check if the input box contains the word "sit"

    The user enters "sit up"

    How do I get Construct to recognize that "sit up" has "sit" in it?

    • Thanks
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From the manual on system expressions:

    find(src, text)

    Find the first index within src that text occurs, else returns -1.

    So, you can use find(textbox.text, "sit") and if it comes up with anything other than -1, the word sit is in there somewhere. Unfortunately, it would also find any words containing "sit", such as situation. If you wanted to make sure it was a specific word you could go with:

    for "loop" 0 to tokencount(textbox.text, " ")

    -Compare to values: tokenat(textbox.text,loopindex("loop")," ") = "sit"

    That would break the string up by spaces (i.e. words, if the person isn't a bad typist like I am) and check each piece individually.

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