# How do I go to a random layout?

Just started using Construct 2? Post your questions here

### » Sun Feb 22, 2015 1:00 am

I'm making a game that is going to have multiple layouts with different map on each one. Every time they complete the task they will go to a random layout for the next map. How do I go to a random layout? I tried using the method use from Joe7 , but it just changes the number then literally changing the layouts. Can you help me? Thanks!

Here is an image of the event sheet of where I'm going to put it and the layout names if needed.
B
10
S
2
Posts: 25
Reputation: 670

### » Sun Feb 22, 2015 1:05 am

Use Go To Layout By Name then put in "Lvl " & floor((random(1) * 4) + 1)

4 being the highest level you have, the second 1 being the lowest
B
48
S
15
G
8
Posts: 603
Reputation: 8,766

### » Thu Feb 26, 2015 1:07 am

EncryptedCow wrote:Use Go To Layout By Name then put in "Lvl " & floor((random(1) * 4) + 1)

4 being the highest level you have, the second 1 being the lowest

Wow it works! thanks! How does it do that? I want learn and an explanation of it would help me a lot.
B
10
S
2
Posts: 25
Reputation: 670

### » Thu Feb 26, 2015 2:06 am

First, keep in mind that the random() expression picks a random number - if you input something like random(1) it will pick a number between 0 and 1 (like 0.222, 0.784, etc).

If you read the expression like it was a math problem, you'll understand better.

What happens first is that a random number is generated between 0 and 1 - then this number is multiplied by 4.

Let's say the random number is 0.7!

0.7 * 4 = 2.8, right?

Then we have floor(2.8+1). So of course, 2.8 + 1 becomes 3.8, right?

Then there's the floor() expression that is used to round down a number. If you use floor(3.8) it will round it down to 3.

So, what the code is saying (in this example) is that the game should go to Layout "Lvl 3" - the & is used to append text (in this case, the "Lvl " text to the "3" number", becoming "Lvl 3".

There are multiple ways you could do this. Check out the expression page for more expressions like that:

https://www.scirra.com/manual/126/system-expressions
B
131
S
45
G
41
Posts: 860
Reputation: 28,641

### » Fri Feb 27, 2015 9:47 pm

Wow. That is pretty cool Andreyin. Thanks! That was really helpful for me to learn C2.
B
10
S
2
Posts: 25
Reputation: 670