Just started using Construct 2? Post your questions here

### » Thu Jan 08, 2015 2:36 am

Hello, I'm trying to set a random number from a range of 1-4 when you collide with a power-up. How do I do this? (as far as I know, all random ranges must start from zero?) But i know there must be a way.
B
4
Posts: 27
Reputation: 254

### » Thu Jan 08, 2015 3:06 am

random starts from what you want it to and ends where you want it to. What you want is "random(1, 4)". This will give you a number in between 1 and 4.
B
48
S
14
G
2
Posts: 254
Reputation: 6,454

### » Thu Jan 08, 2015 4:32 am

Actually, if you want integers, you want: int(random(1,5)), or you can use choose(1,2,3,4). The manual explains the subtleties of the two random() commands.
https://www.scirra.com/manual/126/system-expressions
B
71
S
22
G
240
Posts: 3,733
Reputation: 133,992

### » Thu Jan 08, 2015 4:49 am

thank you guys! i'll try this stuff out.
B
4
Posts: 27
Reputation: 254

### » Thu Jan 08, 2015 7:48 pm

blackhornet wrote:Actually, if you want integers, you want: int(random(1,5)), or you can use choose(1,2,3,4). The manual explains the subtleties of the two random() commands.
https://www.scirra.com/manual/126/system-expressions

Oh, and you can always use round(random(1,4)) as well. I had no idea there was a choose() function though, thank you!
B
48
S
14
G
2
Posts: 254
Reputation: 6,454

### » Thu Jan 08, 2015 9:32 pm

round() won't give you an even distribution of numbers. It's better to use int() or floor() (same thing).
B
71
S
22
G
240
Posts: 3,733
Reputation: 133,992