How do I Search Text on a page?

Get help using Construct 2

Post » Mon Apr 04, 2016 9:50 pm

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
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Tue Apr 05, 2016 12:25 am

Image ImageImage
B
171
S
50
G
180
Posts: 8,394
Reputation: 113,982

Post » Tue Apr 05, 2016 1:19 am

I've never touched that expression before thanks for the tip. I'll check into it! :)
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Tue Apr 05, 2016 2:25 am

@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.
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Tue Apr 05, 2016 2:38 am

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.
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Tue Apr 05, 2016 3:19 am

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.
Image ImageImage
B
171
S
50
G
180
Posts: 8,394
Reputation: 113,982

Post » Tue Apr 05, 2016 3:29 am

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.
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Tue Apr 05, 2016 6:30 am

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.
Image ImageImage
B
171
S
50
G
180
Posts: 8,394
Reputation: 113,982

Post » Tue Apr 05, 2016 8:38 am

maybe you can use windov.find()

Image

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
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Tue Apr 05, 2016 9:21 am

korbaach wonderful work nice to see someone there to help
B
256
S
39
G
15
Posts: 1,983
Reputation: 41,036

Next

Return to How do I....?

Who is online

Users browsing this forum: jezjones24 and 24 guests