How do I Call a section, passage (text) from within a doc?

Get help using Construct 2

Post » Thu Oct 13, 2016 5:45 pm

What I mean is: After importing the text file into Construct 2 and calling it via Ajax, is there a way that I can select a specific part from within this document? Right now I only know how to call the document but I have to create a lot of different documents in order to achieve what I want. It would be nice if I had one long text document and only print on the screens the sections I choose.

Help, please! Thanks!
B
19
S
4
G
2
Posts: 97
Reputation: 2,244

Post » Thu Oct 13, 2016 6:15 pm

You can parse the text in a multitude of ways. The right method to chose depending on your document structure.

What does your document look like ?
B
67
S
27
G
24
Posts: 968
Reputation: 18,571

Post » Thu Oct 13, 2016 6:28 pm

Magistross wrote:You can parse the text in a multitude of ways. The right method to chose depending on your document structure.

What does your document look like ?



This is what I have:

Ajax > Request TEXT.doc ("ReadData" >)
OnTouch > SetText > Ajax.LastData

So far so good. And the document looks like this:

----------------------------------------------------------------------------

The quick brown fox jumps over the lazy dog.

Pack my box with five dozen liquor jugs.

Sphinx of black quartz, judge my vow.

etc

etc

---------------------------------------------------------------------------

Imagine if I have to create 3 separate text documents in the example above, nonsense. Is there a way that I can just grab portions of text from one single document?

Hope I was clear on this. thanks for taking the time.
B
19
S
4
G
2
Posts: 97
Reputation: 2,244

Post » Thu Oct 13, 2016 6:34 pm

You will need some tags or another mechanism to identify portion of the document.

In your example, you could use the "tokenat" expression with "newline" as the delimiter. This way you could retrieve any desired line provided you know its rank in the sequence.
B
67
S
27
G
24
Posts: 968
Reputation: 18,571

Post » Thu Oct 13, 2016 6:44 pm

Magistross wrote:You will need some tags or another mechanism to identify portion of the document.

In your example, you could use the "tokenat" expression with "newline" as the delimiter. This way you could retrieve any desired line provided you know its rank in the sequence.



Thank you! I am fairly new to Construct 2 and game development. Can you tell me how I can do this?

For example, if in a line of my text document the line starts like this: It is a nice day today, Should I add a tag before it?
Like this: (TAG) It's a nice day today... Any special characters here?

And in the Events Sheet, do I need a For loop? Could you just show me what Tokenat would look like on the Event Sheet?

Thanks a lot!!!
B
19
S
4
G
2
Posts: 97
Reputation: 2,244

Post » Thu Oct 13, 2016 7:37 pm

With a tag system, regular expressions will be your friend.

Here's one way you could to it :
https://dl.dropboxusercontent.com/u/700 ... ystem.capx
B
67
S
27
G
24
Posts: 968
Reputation: 18,571

Post » Fri Oct 14, 2016 1:54 am

Magistross wrote:With a tag system, regular expressions will be your friend.

Here's one way you could to it :
https://dl.dropboxusercontent.com/u/700 ... ystem.capx



Magistross, sorry it took me so long to reply. Had a busy day.

Man, I have no words to thank you. Thanks for taking the time. I am still tweaking with it but I think I am going to be able to achieve this soon thanks to you.


Thanks a bunch! Really!
B
19
S
4
G
2
Posts: 97
Reputation: 2,244

Post » Fri Oct 14, 2016 3:15 am

I don't know if I can post this link here, if not I am sorry, but I came across this on Google and thought it was really helpful, too.

https://github.com/jamesqquick/Construct-2/commit/aec86c1e3c127dd604638d4f487517bad09b8619

Magistross thanks again, man. I learned a lot from your .capx file. Outstanding!!!!!!
B
19
S
4
G
2
Posts: 97
Reputation: 2,244

Post » Fri Oct 14, 2016 4:40 am

No problem! Regular expressions may seem daunting at first, but when you understand its usefulness, you can't do without them!
B
67
S
27
G
24
Posts: 968
Reputation: 18,571

Post » Fri Oct 14, 2016 12:11 pm

Magistross wrote:No problem! Regular expressions may seem daunting at first, but when you understand its usefulness, you can't do without them!



That's for sure! They are pretty daunting. Especially for me. I haven't had that much experience. But in the end I was able to use a lot of what you sent me and did some more research too. Ended up calling the lines from the document like this:

trim(tokenat(AJAX.LastData,random(0,300),";"))

I had no idea that all I had to do was to add a separator - (;) hope I used the right term - in my text document.
I didn't know that the lines were counted by default, this line of code above for example, 0 is the first line of my document and 300 is the last, and I even randomized it. It works perfectly.

I thought your example was neat. I will use in one of my projects for sure. But since I wanted to call the lines of text from a file because it had too much content, I came across another way. But definitely what you sent me opened up my mind to get where I got.
So happy!

Thanks!
B
19
S
4
G
2
Posts: 97
Reputation: 2,244


Return to How do I....?

Who is online

Users browsing this forum: Magistross, tarek2 and 2 guests