Random, no repeat array.

Get help using Construct 2

Post » Thu Nov 21, 2013 3:58 pm

Hello,

I have 6 sprites which are identical apart from the UID. They represent all the lettered keys on the keyboard by selecting a random frame of 26.

So each sprite shows a random key out of 26 choices.

The problem I have is that the sprites can easily have the same letter showing, which I can't let happen. For example two sprites show the 'A' letter.

I have got all the different frames in an array with setting...

Array Value at 0 = "A"

and then setting a global variable called 'keys' with...

System Set keys to Array.At(0)


So how do I go about getting a solution to something like this...

If animation frame 0 == animation frame 0 then repeat random selection until nothing of the six sprites matches.

I've started to pull my hair out so if you solve this I will be forever grateful.

Thanks.
B
4
S
1
Posts: 15
Reputation: 455

Post » Thu Nov 21, 2013 4:04 pm

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Nov 21, 2013 4:10 pm

Did you mean that there is a capx on this thread? If so could you please point me in the right direction to it.

Much appreciated, thanks.
B
4
S
1
Posts: 15
Reputation: 455

Post » Thu Nov 21, 2013 4:17 pm

Just click everywhere on every post and see what happens, or read the topic so you notice in what post a link is posted to a capx.

I'll give you a hint.. It's in the third post..LittleStain2013-11-21 16:18:04
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Nov 21, 2013 5:17 pm

http://www.scirra.com/forum/random-frame-uniqe_topic80520.html
this is a better way to do it as you directly input what you want instead of looping till you find something what you want.
If you had 26 objects that need to be filled with a letter, the while loop for the last element could run quite a lot of times.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Thu Nov 21, 2013 6:08 pm

This example uses text. But you can use with sprites too.
https://db.tt/kT2Exjxkmrcgkh2013-11-21 18:08:43
B
21
S
8
G
6
Posts: 177
Reputation: 8,134


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests