# How do I generate a list of possible combinations?

Get help using Construct 2

### » Fri Oct 02, 2015 3:06 pm

Hi I am new to construct and programming in general. With that in mind I had an idea that needed to use the possible combinations of a set with repetition, so I said to myself "yea i can make this in construct!" here I am two weeks later. I have had success with a method to get it done but I think it can be better. Any help is very much appreciated. Thanks!

https://dl.dropboxusercontent.com/u/17757267/combination.capx
My attempt, I made a different event sheet for my other tries, so its all included.
B
6
Posts: 4
Reputation: 270

### » Fri Oct 02, 2015 4:22 pm

One way to do it:

a holds the values
b is a helping array
d keeps the combinations

Care, the repeat will do it all in one tick - if you intend to do that with larger sets, I suggest using some kind of limit of how many iterations you do each tick (mby like 500-1000).
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

### » Fri Oct 02, 2015 6:02 pm

Here's another way. It's basically to change a 10-base number to a "array.width"-base using Array element as symbols.

B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

### » Fri Oct 02, 2015 9:43 pm

Thank you mindfaQ & Magistross I was able to figure out what each line does in each solution.

I have a question for Magistross. When I comment out event 16 "set baseNumber....", why does it still list the combinations successfully? My understanding is that in the "positions" loop that line is what sets the "baseNumber" for the value for the 3 items in the "Combo" variable.
B
6
Posts: 4
Reputation: 270

### » Mon Oct 05, 2015 1:34 pm

Sorry for the delay, @Raven6ix. It's quite impossible that you can still get all the combinations after you comment out the "Set baseNumber" of line 16. This line is responsible for getting all the "digits" right. Otherwise, you will get combinations which all have the same characters appearing at each position. (e.g. "aaa", "bbb", "ccc", "aaa", "bbb", ...)
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

### » Mon Oct 05, 2015 3:04 pm

Thank you @Magistross. I found out why I was getting that "problem", I forgot to switch my event sheet to the one that has your solution in it. As you you said it is indeed impossible to get the combinations.
B
6
Posts: 4
Reputation: 270