How do I check if a textbox contains a word?

0 favourites
  • 4 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • I can check if the textbox has a specific thing in it like if the text is "dog" I can just check for "dog" and find it, but what if I want to check if it just has "dog" somewhere in it? I need it to detect both "dog" and "the dog jumped high", just whenever "dog" is in the text field, activate. How do I do this?

  • if find(text, "dog") is > -1 will tell you if "dog" is in the text. Is that what you want?

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • maybe you can loop your words and find if(x == 'd' && x+1 == 'o' && x+2 == 'g') then there's a dog word inside your text.

  • maybe you can loop your words and find if(x == 'd' && x+1 == 'o' && x+2 == 'g') then there's a dog word inside your text.

    Let's keep everything in C2 event system scope/context shall we?

    Use codah's suggestion to just check whether "dog" exist.

    Use [tokencount("yourText","dog")-1] to check how many occurence "dog" has.

    Use event below if you want to check all index (zero-based) of occurence.

    Condition: Repeat tokencount("yourText"," ")
    Condition: compare tokenat("yourText",loopindex," ") = "dog"
    Action: add <textVariable> with "_"&loopindex[/code:1sejahw6]
    
    Example, if "yourText" is "the dog the dog the dog the dog the dog"
    you should get <textVariable> = _1_3_5_7_9
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)