How do I randomize answer order in a trivia game

Just started using Construct 2? Post your questions here

Post » Thu Dec 03, 2015 3:13 am

I know I should post my file but have not gotten 300 reputation points so cannot post image or file however, I am stymied. I have my Q&A game done and working - questions randomize but I am now trying to randomize the answers i.e. appear in a different order than imported. I have tried different techniques such as using a temp array, loading numbers in randomly (between 1 and 4) and using it to load the answer choices but have not gotten that far - seems I get caught in an infinite loop and without the paid version, not sure where it is getting stuck.

I am going to buy the personal license which will help debugging but wondering if there are any ideas and/or tutorials that someone can point me to (I have search a lot and have come up with shuffling arrays etc... but when I try to incorporate. still getting stuck). I will re-post with file once able but have been struggling for over a week and just looking for some direction.

Thanks!

Bill
B
12
S
4
Posts: 13
Reputation: 918

Post » Thu Dec 03, 2015 9:55 am

@jbcreger2
if your array looks like this
Image

I think this is the simplest way

randomizeAnswerOrder.capx

so... if you set the first answer is always the correct answer
Image
after you randomize question order capx should look similar to this

Example.capx

Image

EDIT:

if you use sprite for answers...basically its the same thing..
just one "spriteAnswer"..write frames in array and set variable correctAnswer to number
Image

randomizeAnswerFrames.capx

EDIT2: ...that is one way.
.if you have specific frames as answers and just want to randomize frames position...

another way is if you want to set one correct frame and three random frames..
you can then use one dimensional array for questions
Image
just be sure your "spriteAnswer" frame 0 is correct answer on first question- Array.At(0),
frame 1 is answer on Array.At(1) etc...
and use another array for frames...

Example2.capx
Image
B
62
S
23
G
7
Posts: 1,470
Reputation: 10,731

Post » Fri Dec 04, 2015 5:10 pm

Thanks for your response - right now I have the questions reading into the array as rows (each question/answer set is its own row). Is there any advantage (or disadvantage) in importing my questions so that each question/answer set is its own column as indicated in your example?

Thanks again for your help!

Bill
B
12
S
4
Posts: 13
Reputation: 918

Post » Sun Dec 06, 2015 1:32 am

jbcreger2 wrote: ...I am now trying to randomize the answers i.e. appear in a different order than imported. I have tried different techniques such as using a temp array, loading numbers in randomly (between 1 and 4) and using it to load the answer choices but have not gotten that far...
:?
jbcreger2 wrote: Is there any advantage in importing my questions so that each question/answer set is its own column as indicated in your example?

Yes..you can easily randomize answers..
and you would noticed that..if you've looked at any of the four examples that I set here...
Image
B
62
S
23
G
7
Posts: 1,470
Reputation: 10,731

Post » Sun Dec 06, 2015 4:06 am

AFAICT there's no difference between using rows or columns, unless you want to be compatible with the code example already given. You could stick with rows, but you'd have to rework the example code to accommodate that.
B
48
S
14
G
4
Posts: 184
Reputation: 5,437


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest