How do I go to a random layout?

Just started using Construct 2? Post your questions here

Post » 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.
Image
B
10
S
2
Posts: 25
Reputation: 670

Post » 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
47
S
14
G
7
Posts: 603
Reputation: 8,151

Post » 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

Post » 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
125
S
43
G
41
Posts: 849
Reputation: 28,260

Post » 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


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests