Make Random Object Spawning Code More Random

Get help using Construct 2

Post » Sat Jul 06, 2013 10:35 am

Hello!

I have made a script where three objects will spawn on one of three 'tracks'. They should spawn randomly scattered across the three tracks, but they are not. Instead, they mostly seem to spawn on the leftmost track, some spawn on the middle track, and none spawn on the rightmost track. Here is my code:



Direct Link :)

Can anybody give me any suggestions?

Thank you!

Orange
B
8
S
2
G
2
Posts: 49
Reputation: 1,894

Post » Sat Jul 06, 2013 11:59 am

random(1,3) outputs a number from 1 to 3, but with the random, you will never have 3 exactly, at most a 2.99 for example. When you cast it as an int, you don't do a "round", you take the int part of the number, making it a number between 1 and 2. What you want is this :
ArrayAt(round(random(1,3)))
B
17
S
8
G
4
Posts: 461
Reputation: 6,157

Post » Sat Jul 06, 2013 3:15 pm

Thank you so much! Seems facepalm-ingly obvious now!
B
8
S
2
G
2
Posts: 49
Reputation: 1,894

Post » Sat Jul 06, 2013 3:21 pm

[QUOTE=OrangeFlash81] Thank you so much! Seems facepalm-ingly obvious now![/QUOTE]
late to your thread but I wasn't aware so don't facepalm yourself too much
:)
B
41
S
12
G
6
Posts: 136
Reputation: 6,372


Return to How do I....?

Who is online

Users browsing this forum: JoyfulDreamer, StillSarah and 22 guests

cron