Random Values Range

Get help using Construct 2

Post » Fri Oct 26, 2012 11:46 am

Hey all, been trying to solve a problem involving random values, and have had a good search through the manual and forums but can't seem to figure this out...

I'm trying to pick a random value between 1 and 3, and are currently using this which works fine (the 'Ceil' rounds the numbers up to whole decimals, which is what i want):

Ceil(Random(3))

But how do I use this to pick only 1 or 3 (i need to exclude 2). I thought it would be something like this, but it doesn't work:

Ceil(Random(1,3))

Thinking it would choose either 1 or 3...I think I'm barking up the wrong tree with this logic.

Does anyone know a way to do this? Totally appreciate the help...FatRat2012-10-26 12:13:42
B
16
S
5
G
2
Posts: 20
Reputation: 2,227

Post » Fri Oct 26, 2012 1:37 pm

You're basically just choosing between two numbers so just do random(2) check if it's over 1 and return 3 else return 1.

random(2) > 1 ? 3 : 1
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
27
S
7
G
4
Posts: 313
Reputation: 4,926

Post » Fri Oct 26, 2012 1:55 pm

Like this: CapX

I would have used arrays and for loops but I'm not sure how to convert:

var array = [1,3];

for(var i = 0; i < 1; i++)
{
//Just a text function to output the text, use whatever you want
console.log(array);
}

to the construct 2 equivalent. lonehangman2012-10-26 13:59:29
B
18
S
9
G
5
Posts: 77
Reputation: 4,946

Post » Fri Oct 26, 2012 5:28 pm

You could use the choose(1,3) function.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Fri Nov 16, 2012 9:55 am

Thanks for the replies (and sorry for the late reply myself, I tried to reply last week but was getting an error on the forums).

I used OddConfections suggestion of this "random(2) > 1 ? 3 : 1" which did exactly what I needed in the end.

The 'choose(1,3) option sounds useful though. I didn't know about that function.FatRat2012-11-16 09:56:18
B
16
S
5
G
2
Posts: 20
Reputation: 2,227


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests