I want to pick a word from a text file.

Get help using Construct 2

Post » Wed May 13, 2015 8:00 pm

Suppose my text file has "Hi my name is [myname]."
now i want to pick the word which is covering by the "[]" bracket.
I use File Reader plugin to read the text file and Advance text box to show the data on construct 2.
If someone know how can i do it please help me...
B
6
S
1
Posts: 62
Reputation: 524

Post » Thu May 14, 2015 2:40 am

do a search on Regex in the manual.. there are a bunch of functions to help you process a string..
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Thu May 14, 2015 2:42 am

you cand do that by calling in the text, the word after a [comma] or a [dot] or a [-] and the text automatically will read the next word, had a capx of that is really simple thing actually! let me find it and will give it to you
B
70
S
20
G
67
Posts: 1,316
Reputation: 42,305

Post » Thu May 14, 2015 7:34 am

RegexMatchAt(yourstring,"Hi my name is \[(\w+)\]\.","i",1) (only works when it's one word, no spaces)
RegexMatchAt(yourstring,"Hi my name is \[([\w ]+)\]\.","i",1) (spaces are allowed)
RegexMatchAt(yourstring,"Hi my name is \[(.+)\]\.","i",1) (any characters are allowed, must be at least one character)

one of these should do the job, depending on what you need
Last edited by mindfaQ on Thu May 14, 2015 10:39 am, edited 1 time in total.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Thu May 14, 2015 7:54 am

mindfaQ wrote:RegexMatchAt(yourstring,"Hi my name is \[(\w+)\]\.","i",1) (only works when it's one word, no spaces)
RegexMatchAt(yourstring,"Hi my name is \[([\w ]+)\]\.","i",1) (spaces are allowed)
RegexMatchAt(yourstring,"Hi my name is \[([\w ]+)\]\.","i",1) (any characters are allowed, must be at least one character)

one of these should do the job, depending on what you need

if you give me a sample capx file it will be very helpful for me.
@mindfaQ
B
6
S
1
Posts: 62
Reputation: 524

Post » Thu May 14, 2015 8:00 am

gamecorpstudio wrote:you cand do that by calling in the text, the word after a [comma] or a [dot] or a [-] and the text automatically will read the next word, had a capx of that is really simple thing actually! let me find it and will give it to you

waiting for the capx. please send me it :)
B
6
S
1
Posts: 62
Reputation: 524

Post » Thu May 14, 2015 8:42 am

I won't post a capx, it's a basic system expression - go through the very basic tutorials, if you don't know how to use those.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Thu May 14, 2015 9:22 am

I also waiting capx :D
seriously :oops:

...le'ts say i have Unknow Text :

"unknown text unknown [my 9name$] text unknown unknown length text unknown text unknown text unknown length !"

how simple extract string between brackets?
(in one action)

..i can find "[" & "]" and then extract string between brackets...
or use something like
RegexMatchAt(UnknownText.Text, "\[[^\(\r\n]*\]", "g", 0) and then cut the brackets...

but I can not figure out..how extract string between brackets...in one action :?
Image
B
64
S
23
G
7
Posts: 1,482
Reputation: 10,825

Post » Thu May 14, 2015 9:44 am

Ok bro.

i set the Expressions on a Text object (as set text) : RegexMatchAt(AdvancedTextBox.Text,"\[[(\w+)\]]\.","i",1)

and add "[[word]]" on my txt file.

but when i load my text file it it set nothing on the Text :(
@mindfaQ
B
6
S
1
Posts: 62
Reputation: 524

Post » Thu May 14, 2015 10:43 am

Of course like always with regex the necessary complexity depends on the data you can expect / want to work with.

If the string always looks like "Hi my name is [myname].", a simple RegexMatchAt(AdvancedTextBox.Text,"Hi my name is \[(.+)\]\.","i",1) or even RegexMatchAt(AdvancedTextBox.Text,"\[(.+)\]\","i",1) will work.

If you expect multiple [] in the text and you want to match them all plus wanna filter out newlines, it could look like this:
https://copy.com/rITBhCmSQaOU7RCN
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests