How do I show random image [no repeat] from array?

Get help using Construct 2

Post » Mon Sep 29, 2014 5:57 am

Hi,

I see from other forum questions & tutorials that there are multiple ways of doing this, and that this is a core C2 skill.
But I haven't been able to make it happen yet.

I'm making a simple language game.

Example of play:

The player sees a picture of a duck and 2 words: 'Cat' and 'Duck'.
When he clicks on the word that matches the picture, a new picture appears (let's say, a house), with 2 new words 'House' and 'Telephone'.


What's the easiest way to stop correctly answered questions from repeating?
B
7
S
1
Posts: 32
Reputation: 514

Post » Mon Sep 29, 2014 8:05 am

how about using booelan variable?
if the word matches with the picture, then set booelan to true.
then generate a new picture with false booelan.
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
64
S
14
G
3
Posts: 292
Reputation: 7,188

Post » Mon Sep 29, 2014 9:48 am

Thank you for your reply.

That sounds good- but I don't know how to integrate that solution with my current set up.

Image


I'm happy to start again- but could you elaborate a little more?
B
7
S
1
Posts: 32
Reputation: 514

Post » Tue Sep 30, 2014 8:52 am

1. on start of the layout, set your array to 1, 2, 3... till the number of your questions.
2. then use function to set random number from(1-end) to show a random question.
3. if the answer is correct, change the value to "solved"
.
then, to generate a new question, call the function again, but if array index-X has been solved, call the function till you find an unsolved question.
.
this is not the best method, but I hope you can get an enlightment from this.
sorry for my bad english.
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
64
S
14
G
3
Posts: 292
Reputation: 7,188

Post » Tue Sep 30, 2014 12:17 pm

Thank you very much,
I'll try that!
B
7
S
1
Posts: 32
Reputation: 514

Post » Tue Sep 30, 2014 12:35 pm

a little suggestion to speed up the process of item picking. After one question is completed, instead of flagging it as "solved", delete it from the array.

This will prevent this possible case:
Your array has 1000 items at the beginning, you completed 999 items, and now the loop might need quite long to find the last possible question to be displayed.

When you remove the solved items entirely and just pick a random item from (0-width of array), you will always pick a valid one :)
B
44
S
10
G
8
Posts: 437
Reputation: 6,473

Post » Wed Oct 01, 2014 7:24 am

Thank you. It'll be a few more days before I can try any of this out (I'm travelling to another country)
But those sound like good ideas to a problem I've been avoiding for ages.
B
7
S
1
Posts: 32
Reputation: 514

Post » Sun Oct 05, 2014 4:49 am

nice idea ubivis..
I almost forgot that you can delete an index of array in C2 :D
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
64
S
14
G
3
Posts: 292
Reputation: 7,188


Return to How do I....?

Who is online

Users browsing this forum: dop2000, irina, Yahoo [Bot] and 7 guests