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,324

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
84
S
27
G
69
Posts: 4,920
Reputation: 49,032

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,324


Return to How do I....?

Who is online

Users browsing this forum: lamar and 3 guests