Select lines from a .txt file to display

Get help using Construct 2

Post » Fri May 10, 2013 11:37 am

Hi,I'm making a quiz game and to make it easier to get the questions in the game I am usinge AJAX to load a .txt file.

I have so far managed to get the .txt file loaded and the first question to display in my text box by setting text to AjaxLastData.
Even that took me ages to work out because I am such a noob.

Is there an easy way to set the text to specific lines in the .txt so I can just have a list of questions that can be selected?

Please don't tell me I need an array because that is definitely beyond me!

Thanks,

Elliot
B
5
S
1
Posts: 19
Reputation: 1,173

Post » Fri May 10, 2013 4:11 pm

AjaxLastData contains the integrality of your text file. You will have to parse it to retrieve the lines you want. I guess you could tokenize the data with the "newline" character (using tokenat). But it will be practicable only if you have one question per line. Otherwise you might want to take a look at XML.
B
45
S
16
G
18
Posts: 845
Reputation: 13,673

Post » Fri May 10, 2013 4:39 pm

I suggest you either using a special char and tokenate at it

Imagine this:

#TITLE OF QUESTION 1
Blah, blah, blah
Answers
1. X
2. X
3. X

#TITLE OF QUESTION 2
...

You can get first question by using tokenat(yourtext,1,"#").

And, inside the first question, you can get first answer by finding newline&"1.", second by finding newline&"2.", etc.

I use a similar scheme in my game "caballo", where the "question" text is inside a textbox (I made that before files were avalable)

http://www.scirra.com/arcade/puzzle/1090/caballo

You could use XML or JSON instead if you want to make something more standarised, of course.arcalaus2013-05-10 16:42:02
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Fri May 10, 2013 8:30 pm

I just want to add I've uploaded to the arcade the program I use to debug my xml files, just in case you decide to use XML.
It is here
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Sat May 11, 2013 10:33 am

Thanks Arcalaus- I think that will do the trick. I don't even need the answers- it's all very simple.
I'll be setting it up on Monday- hopefully this will be the end of this thread!

Cheers ;)
B
5
S
1
Posts: 19
Reputation: 1,173

Post » Sat May 11, 2013 10:36 am

Cheers Magistross- the questions are all on new lines so a newline parse will be fine!
B
5
S
1
Posts: 19
Reputation: 1,173


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 16 guests