How do I can shuffle an array?

Get help using Construct 2

Post » Tue Jul 19, 2016 5:39 pm

Hello.

I can obtain a new shuffled array from another one ('temp') when a botton is pressed. I use a function but it doesn't work when I call it again ('temp' array is empty). What am I doing wrong?

Image

And this is the result in a browser (it works the first time).
Image

Thanks in advance.
B
3
Posts: 4
Reputation: 183

Post » Tue Jul 19, 2016 6:40 pm

As you said, your temp array is empty the second time you call shuffle... So before you shuffle, you need to rebuild your temp array. Either copy your current array to the temp array to shuffle the remaining cards, or populate it from scratch.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Tue Jul 19, 2016 7:35 pm

Thanks for your reply. I call init function and then shuffle function but it doesn't work.
B
3
Posts: 4
Reputation: 183

Post » Tue Jul 19, 2016 8:37 pm

Try setting the size of the temp array upon calling the function, rather than in the loop?
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Wed Jul 20, 2016 7:24 am

That works! I set the size of the temp array at start of init function, out the loop.
Thanks very much.
B
3
Posts: 4
Reputation: 183

Post » Wed Jul 20, 2016 7:59 am

One more question about this code:

How can I asign the elements of 'new' array to the five objects in a loop? I can only add action to each object, one by one.

Thanks again.
B
3
Posts: 4
Reputation: 183


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests