How do I Search Text on a page?

0 favourites
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • Hi everyone,

    This I realize is an un-game-like request in many cases.. but does anyone know if there is a way to search text like you would with control+f ?

    I literally want to just be able to do that. someone type a word in a text field (which C2 has) and enter to jump to a given spot where that text is located.

    Thanks,

    Caleb

  • I've never touched that expression before thanks for the tip. I'll check into it!

  • newt ok so i have a project setup.. the best i could come up with is to do a system/compare two values.. but i'm not sure what else could be done.. my initial test.. i'm able to use a text box.. enter text.. hit a search button which saves that value to a var..

    my next step would (i think) be to try and do a compare two values.. the text from the information textbox (i put a big speech in there) to the text from the global variable.

    There must be some other step in the process i'm not following.. part of the challenge too is not knowing how to actually use Regex.. i see it on the link you shared:

    RegexSearch(String, Regex, Flags)

    Return the index of the first character in String where a match for Regex with Flags could be found.

    i assume the String they want would be the information.text that i have in my textbox object.. but what is the Regex thing they want? what are the flags? those concepts are foreign to me in this context.

  • Also I saw:

    find(src, text)

    this seemed possibly promising as well but again i'm afraid i don't understand how to frame an expression like this to do something meaningful with it.. like say i did a search for the word "hammer" and the text i search is very long.. maybe 4-5 mobile phone screen sizes of information and the word hammer appears 1/2 down.. naturally i'd want the screen to scroll down to that point so a person can quickly get the information they need.

  • Well you can estimate a word's position by its index in a string using something like tokencount.

    Given that you know the height of the textbox, and its global position.

    No idea on scrollable content however.

    I think that would be a feature request.

  • ok yea i see what you mean about estimating a position..

    any ideas on how i should properly use that expression to search text?

    my question is:

    RegexSearch(String, Regex?, Flags?)

    I get the String value.. in here i can use "information.text" which would be the text in my information object (a text box).. but what do they mean for me to put in the regex and flag fields?

    Also thank you so much for your insite! This is tremendously helpful.

  • I'm not sure what you are looking for. But find(src, text) will get you the index of the last letter.

    http://regexr.com/

    Is a nice tool to test regex.

  • maybe you can use windov.find()

    windowFind.capx

    Of course, this is just the start..need to realize how to Scroll textarea to selected word..add another textBox and pull word to variable...etc

  • korbaach wonderful work nice to see someone there to help

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • korbaach and newt thank you both. That's super helpful! I'll explore this and see how far I can get with it. I feel like understanding how this example works might help give me ideas of how to address other features!

  • wow i got a chance to peek at the example.. you're using actual javascript.. that's awesome. i would have never been able to pull that off.. i may explore other ways to get a similar result, but this is still a fascinating and very helpful to realize how a solution could be found.. I have a developer partner that I might be able to lean on to help with JS coding to further improve the behavior in my case, but this example sheds a ton of light.. I was thinking i could do it purely through C2 expressions / actions.. but that's not the case.

  • Thank you Lordshiva1948

    part12studios I doubt that this can be done only with C2 expressions / actions...

    but I could be wrong..

    updated capx: windowFindText.capx

    still no idea.. how to scroll to selected word..

  • yea that's great to know.. sometimes it's just good to know "hey you can't do that with C2 out of the box". man that's so badass..

    ok so in terms of scrolling to a position.. are you able to set a scroll bar position? i'm totally asking this as a novice in this regard. I wonder if the means in which you're able to scroll too based on the bar position couldn't be hijacked.. even if the result was not pixel perfect it would probably be close enough.. like if there were 100 words in the text field.. if the word you find is word 50 you know roughly 50% down? a little math needed if the number was like.. 250 words.. or 41..

    btw, how are you posting animated scripting events like that? that is also pretty awesome

    Thanks!

    Caleb

  • just for a moment I thought I have a solution..

    ..but ..

    first..getSelectionRange.capx

    then..setCaretPosition

    that will automatically scroll textBox to "cursor"

    but I simply can not force to work together..

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