Place 5 random values in an array? I'm going crazy

Get help using Construct 2

Post » Wed Aug 28, 2013 11:44 am

Help!!

I think I'm going crazy because of this. I don't know, it seems I'm missing something pathetically simple.

I want to place the word "coin" five times in an array randomly (in empty cells). I tried like this:



But all it does is placing "coin" in the first cell of the array every single time. Any ideas?
B
16
S
7
G
1
Posts: 158
Reputation: 3,125

Post » Wed Aug 28, 2013 1:04 pm

The title should say "Place one value 5 times in an array randomly" but the system won't let me edit the post ('too little reputation to post a link'). But it did let me post it to begin with, oh well...
B
16
S
7
G
1
Posts: 158
Reputation: 3,125

Post » Wed Aug 28, 2013 2:01 pm

first initialize the array with " "

than just:
+ repeat 5 times
array set value at random(0, array.length)to coin


B
15
S
6
G
6
Posts: 512
Reputation: 5,555

Post » Wed Aug 28, 2013 2:01 pm

Should work. The exception is that you also need to set RandomPlace BEFORE the while loop, otherwise your first default index is always 0.
Coin5Times.capx

Edit: and be sure your array is large enough in the first place.blackhornet2013-08-28 14:04:18
ImageImageImage
B
71
S
21
G
233
Posts: 3,696
Reputation: 130,368

Post » Thu Aug 29, 2013 7:02 am

Thanks!

@Darklinki, your solution is fine but it doesn't prevent placing a coin multiple times in a cell.

@Blackhornet, that .capx saved my sanity! It turned out it was all because of a syntax error. As you can see in the screenshot I was making the condition "value at Board.At(RandomPlace)" which doubles the AT. When changed to simply "value at RandomPlace" - works like a charm.
B
16
S
7
G
1
Posts: 158
Reputation: 3,125

Post » Thu Aug 29, 2013 9:21 am

@pirx sorry didnt know you want that
B
15
S
6
G
6
Posts: 512
Reputation: 5,555

Post » Thu Aug 29, 2013 1:51 pm

You also need the extra Set RandomPlace or you will always get a value at index zero.
ImageImageImage
B
71
S
21
G
233
Posts: 3,696
Reputation: 130,368


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests