How do I pick non-duped frames from multiples of an object

Get help using Construct 2

Post » Thu Nov 13, 2014 1:44 am

Hi All,

Hoping someone may be able to help with this little problem I'm trying to solve.

I have one object with 10 frames, each frame has a different colour box. I have 3 instances of this object on my layout and I want each object to jump to a random frame, but not duplicate. For example, Red-Green-Blue and not Red-Blue-Blue.

I have been looking at arrays and the various tutorials and forum posts and I think that arrays are the way forward however it's not my strong point and I don't feel I fully understand them and while I can create an array of random numbers and can get the objects to pick up a number from the array, they all pick up the same number rather than a different number each. So all three objects always jump to the same frame. I had a look at the tutorial about not picking duplicate numbers but I think my struggle is actually applying the each number to an instance of the object and setting the frame number.

Any thoughts or ideas would be greatly appreciated and if I'm being an idiot and going about it completely the wrong way, please do say so!
B
4
Posts: 2
Reputation: 204

Post » Thu Nov 13, 2014 4:18 am

I whipped up an example for you right quick to show one solution to the problem. Essentially, you have to assign colors to sprites in turn, then check each successive sprites new color against all of the previously assigned ones for uniqueness. If it's not unique, you assign a new color to that one and do the check again. Theoretically it could get stuck in this assign/check cycle forever, but unless you have an unrealistically large amount of objects you're assigning unique colors to, there shouldn't be any issues.

checkUnique.capx


EDIT: Accidentally uploaded an old version.
You do not have the required permissions to view the files attached to this post.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Thu Nov 13, 2014 11:45 am

Hey Linkman, thanks so much for showing me this, I've been playing around with it this morning and it is a great way of doing it! I wasn't even close to looking at it that way as I was convinced I needed various arrays and such, I really appreciate you taking the time to whip up the example, it's extremely helpful.
B
4
Posts: 2
Reputation: 204


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests