Randomizing order of words displayed from an array

Get help using Construct 2

Post » Thu Feb 06, 2014 11:46 am

How do i do that? As in randomizing order of words displayed from an array.

I'm building a quiz game, and thanks to the example given by @procrastinator, I have made good progress, But I would like to randomize a the options of answers given, and how is it possible?

For example, after loading the file questions.txt using Ajax, the format i'm using in the file is question,ans1,ans2,ans3,ans4,ans5,correct answer index.

So the order the answers will be displayed in the answers box is by the order 1-5, the question is how to randomize it? I don't want them in the order 1,2,3,4,5; instead i want them to be randomly jumbled up, 2,1,4,5,3. How is it possible to do that?

If you're interested in why I need to do this, it is because I'm doing the game for revision and sometimes I've seen a certain question so many times I kinda remember the 'location' of the answer to that question without even needing to look at the answers or thinking. I want to avoid that, hence this.
B
5
Posts: 11
Reputation: 270

Post » Thu Feb 06, 2014 12:33 pm

If you feed your array with datas just like the txt files, you should have the question in index 0, answers 1 to 5 in index 1 to 5, and the answer in index 6.

I don't exactly know how you use those datas to display on screen, but it should be a text object per answer if I'm right. If this is the case, the solution is simple :
- add a "answer Index" variable to each text
- when you want to display a new question, empty all the text elements and set their answerIndex to 0
- then, for i = 1 to 5, select a random instance of a text element that is currently empty, and set it to "ans"&i. Put the "i" loopIndex in the "answer Index".
This way, you will have the answers randomly appearing on screen, but will still keep track of what answer is the right one.

I'll send a capx soon to illustrate.
B
17
S
8
G
4
Posts: 473
Reputation: 6,191

Post » Thu Feb 06, 2014 12:51 pm

@Demonchest here is the capx.
B
17
S
8
G
4
Posts: 473
Reputation: 6,191

Post » Thu Feb 06, 2014 2:10 pm

@Guizmus my answers are actually all in the same text object, I tried your example and it didn't work in my case. Any ideas how i can work it out?
B
5
Posts: 11
Reputation: 270

Post » Thu Feb 06, 2014 2:26 pm

@Guizmus i'm trying to modify it to the multiple text object layout as i now see that it solves another problem i'm looking at, however i cant figure out how did u create 5 text objects and group them as 1?
B
5
Posts: 11
Reputation: 270

Post » Thu Feb 06, 2014 2:59 pm

@Demonchest I only created 1 text object, and used it 5 times in the layout, that's all. They are all the same text objects for the answers.
I created also a text object for the question, and a last one for the output, those are different.
The events are commented, but don't forget to look at the Answer object proprieties : it has a variable used in the events.

As for going from 1 text object to 5... it all depends on how you implemented it in the first place. I didn't know you only used one, sorry for this.

I want to help you to implement this, but it would be easier if I had a screenshot of the events or a capx.
B
17
S
8
G
4
Posts: 473
Reputation: 6,191

Post » Thu Feb 06, 2014 3:25 pm

@Guizma http://www.mediafire.com/download/iwngpwnkbkqsaym/zt_v1.22.capx
here's the link to my file. Modified it from @procrastinator 's example. I've only just started using this program so i've still got much to learn. Please tell me how to make it behave like yours
B
5
Posts: 11
Reputation: 270


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], rollyzz and 44 guests