Reading lines from a text-file.

For questions about using Classic.

Post » Mon Sep 08, 2008 5:28 pm

I couldn't figure out how to put the title, and I guess I can't explain it too well, but here goes.

Is there a way to read specific lines from a text file?

If I had a file called positive.txt that would be like this:

cool guy
smart
pretty
nice

and I want a text to change into one of those at random, how would I do it? Is it even possible?

Oh, and I'd love to have it so that if you add a line, it can automatically tell that there is a new line, so you can add stuff into the file without changing the application in Construct. So it kind of counts the lines or something.

There, I hope you understood.
B
2
S
1
G
4
Posts: 35
Reputation: 1,270

Post » Mon Sep 08, 2008 5:44 pm

The only way I've managed to do something like this is by loading the text file using the list object. This will load the text file, giving each line it's own seperate line in the list object, allowing you to change whichever one you want.
Moderator
B
98
S
36
G
19
Posts: 1,584
Reputation: 17,717

Post » Mon Sep 08, 2008 8:49 pm

[quote="linkman2004":bfti4f6b]The only way I've managed to do something like this is by loading the text file using the list object. This will load the text file, giving each line it's own seperate line in the list object, allowing you to change whichever one you want.[/quote:bfti4f6b]

For me the list-object just remains empty, no text, but the vertical scroll bar goes smaller if I make it add the file when I click and click a few times and it says the correct amount of lines.
B
2
S
1
G
4
Posts: 35
Reputation: 1,270

Post » Mon Sep 08, 2008 9:02 pm

[quote="Sgt Tupelo":12f37h5v]For me the list-object just remains empty, no text, but the vertical scroll bar goes smaller if I make it add the file when I click and click a few times and it says the correct amount of lines.[/quote:12f37h5v]

That's strange. I tested it just now, and it loads just fine. :? Are you just using the "Load from file" action?
Moderator
B
98
S
36
G
19
Posts: 1,584
Reputation: 17,717

Post » Mon Sep 08, 2008 9:03 pm

Nevermind, got it to work, and it works flawlessly!
B
2
S
1
G
4
Posts: 35
Reputation: 1,270

Post » Mon Sep 08, 2008 9:16 pm

Glad I could help. :)
Moderator
B
98
S
36
G
19
Posts: 1,584
Reputation: 17,717

Post » Mon Sep 08, 2008 10:43 pm

You could also use the Text Manipulator which can read line by line.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Mon Sep 08, 2008 11:01 pm

[quote="Rich":3bpwd2js]You could also use the Text Manipulator which can read line by line.[/quote:3bpwd2js]

I couldn't figure out how to make it read any other line than the last line.

But list-objects saved my day! It works like a charm now!
B
2
S
1
G
4
Posts: 35
Reputation: 1,270

Post » Tue Sep 09, 2008 8:08 pm

There was a bug in this, but it's fixed now.

In the next build, you can use 'Read file line by line' and then in a new event the 'On line read' will trigger for every line.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Thu Apr 12, 2012 3:06 pm

Hi i need to do this exact thing too but i don't quite know what you mean by using the list object. Is this a feature only available in the none free version?

Nor do i understand where to find or even write Read file line by line
FookinNora2012-04-12 15:12:35
B
4
Posts: 10
Reputation: 600

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests