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
8
Posts: 339
Reputation: 9,314

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
79
S
24
G
52
Posts: 4,724
Reputation: 39,711

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
8
Posts: 339
Reputation: 9,314


Return to How do I....?

Who is online

Users browsing this forum: anty21ro, Radulepy, tarek2, TiagoCesar and 20 guests