Random ID assignation - surprisingly difficult

Get help using Construct 2

Post » Sat Jul 07, 2012 10:10 am

Hi there

I've got a question that didn't sound hard to me when I started, but has actually turned out quite tricky. Basically I have X buttons, and I need to randomly assign them IDs from 1 to X. However, no two buttons can have the same ID.

How can this be done with events?

Cheers!
B
55
S
12
G
9
Posts: 339
Reputation: 9,574

Post » Sat Jul 07, 2012 11:41 am

Create an array.

Use a while loop :)
B
22
S
7
G
3
Posts: 189
Reputation: 4,270

Post » Sat Jul 07, 2012 11:49 am

+For each button order by random(1) ascending
--- button: set id to loopindex
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849

Post » Sat Jul 07, 2012 3:36 pm

Thanks guys. I managed to get it working with an array - but r0j0hound's solution is probably the most elegant way to do it. I'll keep it in mind for future!
B
55
S
12
G
9
Posts: 339
Reputation: 9,574


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 7 guests