How do I go to a random layout?

0 favourites
  • 5 posts
From the Asset Store
The ultimate voice pack filled with 1,536 files of .......wav and mp3 of individual numbers, letters, and words (that go
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • 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

  • Wow. That is pretty cool Andreyin. Thanks! That was really helpful for me to learn C2.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)