How do I randomly place numbers in an array?

Get help using Construct 2

Post » Thu Feb 23, 2017 6:13 pm

0 multiplied by 0 is 0


That's okay, I need a single 0 as one of the results.

When the tutorial program is run, it locks up without displaying the results like normal. Same thing with choose(0,2,4,6,8,10). It will not give me a result. If i swap out the 0 like choose(1,2,4,6,8,10), it works, but no zero. I can get this to work though, choose("0","2","4","6","8","10").
B
39
S
18
G
5
Posts: 98
Reputation: 5,621

Post » Thu Feb 23, 2017 6:22 pm

Matthew de wrote:
0 multiplied by 0 is 0


That's okay, I need a single 0 as one of the results.

When the tutorial program is run, it locks up without displaying the results like normal. Same thing with choose(0,2,4,6,8,10). It will not give me a result. If i swap out the 0 like choose(1,2,4,6,8,10), it works, but no zero. I can get this to work though, choose("0","2","4","6","8","10").


That is because you are trying to multiply by zero. Change it to 1 through 11 and then subtract one from the result and you will get your chosen range.
Banned User
B
23
S
6
G
58
Posts: 1,229
Reputation: 34,540

Post » Thu Feb 23, 2017 6:34 pm

Where am I multiplying zero by zero? The only multiply I can see is, floor(Random(0,6))*2.

I can't get choose(0,2,4,6,8,10) to work either, I just want it to be able to pick the zero and give it to me.
B
39
S
18
G
5
Posts: 98
Reputation: 5,621

Post » Thu Feb 23, 2017 6:44 pm

Matthew de wrote:Where am I multiplying zero by zero? The only multiply I can see is, floor(Random(0,6))*2.

I can't get choose(0,2,4,6,8,10) to work either, I just want it to be able to pick the zero and give it to me.

Random uses the first number in the range which you have as zero and you have 0*2 and you can't multiply 0.

Change range to 1,8 and then subtract 1 from the result and it will give you range 0 to 6.
Banned User
B
23
S
6
G
58
Posts: 1,229
Reputation: 34,540

Post » Thu Feb 23, 2017 7:12 pm

But this does not:
floor(Random(0,6))*2
choose(0,2,4,6,8,10)

https://www.dropbox.com/s/c5h01uk2tybyc ... .capx?dl=0

Both work fine ?
B
33
S
18
G
27
Posts: 2,441
Reputation: 20,346

Post » Fri Feb 24, 2017 6:43 am

I actually got the floor(Random(1,6))*2 working with subtraction. So I am able to achieve the result that I wanted.

However, I am still puzzled why choose(0,2,4,6,8,10) will not work for me. At this point I am just trying to understand the limitations.

You can see in the capx provided. Toggle between the two choose options to see the difference.
https://www.dropbox.com/s/jprcxp4vwn3iuo1/RandomNumbers.capx?dl=0
B
39
S
18
G
5
Posts: 98
Reputation: 5,621

Post » Fri Feb 24, 2017 7:39 am

When choose(0,2,4,6,8,10) is the one running, it just gives me a black screen. Why can't it just choose 0 and enter it into the array?


On start of layout - array is not realy empty :
Image

you can't place 0 -because array already contains number 0

Image

so you first needs to fill the array with a different value

Image
Image
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

Post » Fri Feb 24, 2017 8:41 pm

Wow, that's the exact answer I was looking for! I did always assume that the array fields were completely empty and now it makes perfect sense.

Thank you everyone who help me figure this out.
B
39
S
18
G
5
Posts: 98
Reputation: 5,621

Previous

Return to How do I....?

Who is online

Users browsing this forum: ivanski1983, KTML5, Yahoo [Bot] and 3 guests