How do I stop the same layout from showing up

0 favourites
  • 7 posts
  • Hi There,

    I have tried researching this but simply cannot find the answer. Currently I have set my layouts to randomly display by "Layout " & ceil(random(14) + 3) but I would like (if possible) that the same layout doesn't show up again.

    Is this something that is possible?

    Everyones help would be amazing!


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey ai4ns,

    It sounds like you want to show a random layout as if drawing it from a deck of shuffled cards, and allowing the deck to run out over successive draws.

    We can use the Array object to get this effect. At the start of the game, we can fill it with layout names (making our deck), and then pull the layout names (cards) out of it at random, and discard them as we jump to that layout.

    We want a simple 1-dimensional array. The Array object in Construct 2 will work just fine, but be aware that it's a 3-dimensional array, a cuboid with X-width, Y-height, and Z-depth. So we'll just need to be careful.

    To get a 1-dimensional array, we will only be dealing with the X-width axis, so we will set the Y-height and Z-depth both to "1" and forget about them.

    Add an array object to the layout.

    On start of layout, set its (x,y,z) size to (0,1,1).

    (Just as a brief example, at this point if we were to add 5 cells into the X axis, the array size would then be (5,1,1), a 1 by 1 snake that is 5 cells long. Written out, [ cell-0 , cell-1 , cell-2 , cell-3 , cell-4 ].)

    Okay, so we have a (0,1,1) array.

    Still on start of layout, we run a loop to create 1 array entry for each layout you want to go to (3 to 14), and add (push) them into the array. Rather than filling the array with layout numbers (since I'm not sure you can jump to a layout by number), lets use the layout names. For this example I'll assume that layouts 3 to 14 are named "p1" to "p12". ("p" for page).

    We get:

    [ p1 , p2 , p3 , p4 , p5 , p6 , p7 , p8 , p9 , p10 , p11 , p12 ]

    Now when you want to choose a new layout, we pick one of those cells at random and save the cell number we picked in a custom local variable "cellIndex", then store the number we find in that cell in another local variable "cellValue". Finally, we remove the cell at "cellIndex" from the array. We can then jump to the layout "cellValue".

    So the whole event will look like this:

    Event: <We need to jump to a new layout>

    Action: [System]: Set local variable "cellIndex" to: floor( random( Array.Width ) )

    Action: [System]: Set local variable "cellValue" to: Array.At( cellIndex )

    Action: [Array]: Delete index cellIndex from X axis.

    Action: [System]: Go to layout (by name) cellValue.

    So as an example of how this would work:

    Starting with

    [ p1 , p2 , p3 , p4 , p5 , p6 , p7 , p8 , p9 , p10 , p11 , p12 ]

    We pull out a random cell "p3" and go to that layout. And the array is now missing that cell.

    [ p1 , p2 , p4 , p5 , p6 , p7 , p8 , p9 , p10 , p11 , p12 ]

    Now if we pull out another random cell "p11", we get

    [ p1 , p2 , p4 , p5 , p6 , p7 , p8 , p9 , p10 , p12 ]

    etc... Eventually we have used up all the cells.


    Sorry the explanation is verbal rather than a capx.

    Anyway, I hope that helps.

  • Thanks for the reply!! It all make sense but I am a little confused on what I should be entering in this section:

    [quote:3vf4cp29]Still on start of layout, we run a loop to create 1 array entry for each layout you want to go to (3 to 14), and add (push) them into the array. Rather than filling the array with layout numbers (since I'm not sure you can jump to a layout by number), lets use the layout names. For this example I'll assume that layouts 3 to 14 are named "p1" to "p12". ("p" for page).

    What I've Done:

    PUSH: Where: Front, Value: **Not sure what format**, Axis: X

    I am just confused in what format. I tried [ p1 , p2 , ... ] etc but it said syntax error. Am I suspose to do "p1, p2, p3" (with quotes?)

    Once again thanks for all your help!

  • No problem,

    Sorry I was a bit vague there. So, when I wrote out the "[ p1 , p2 , p3]" looking depictions of the array, I was just using this as a shorthand for showing what was in the array, so it's not a formal way of representing data in Construct 2.

    To add each item into the array we push them in one at a time. That may sound tedious, because it is almost the same action 12 times in a row, push "p1", push "p2", push "p3", etc, but fortunately we can use a loop to do that tedious part for us.

    To push all the values "p1", "p2", "p3", etc into the array we can do the following.


    * On start of layout.


    * [Array] Set size to (0,1,1).


    * On start of layout.

    * Loop from 1 to 12.


    * [Array] Push: Where <back>. Value <"p" & loopindex>. Axis <X>

    (without the < > angle brackets)

    Image version:


    A few notes on what's going on:

    The loop event runs from 1 to 12, meaning it will run its actions 12 times. Construct gives us a variable named "loopindex" that we can use in expressions, to get the number of the current loop step. On the first of our 12 loop steps, loopindex = 1, and on the last step loopindex = 12.

    So, that loop will run the action multiple times, creating the following effect:

    * [Array] Push: Where <back>. Value <"p" & 1>. Axis <X>

    * [Array] Push: Where <back>. Value <"p" & 2>. Axis <X>

    * [Array] Push: Where <back>. Value <"p" & 3>. Axis <X>


    * [Array] Push: Where <back>. Value <"p" & 12>. Axis <X>

    What is this <"p" & loopindex> thing?:

    "p" & 1 creates "p1"

    "p" & 2 creates "p2"

    "p" & 3 creates "p3"

    etc ...

    Push Back vs Front?:

    It actually doesn't matter if we push from the back or the front when adding the values into the array, since they will be pulled back out randomly. However, if we push from the back, we'll get all the items in order, in case that becomes important later.


    Remember, you can run the game in debug mode if you want an easy way to look inside the array, to verify that it got set up correctly. You could also use another loop to read the values back out into a text object.

    Anyway, I hope that clarifies things.

  • Sweet! Thanks for the clarification. You sure know how to explain stuff haha Everything seems to be randomising now so thank you so much! Sorry to keep bugging you but this will be the last time! I've checked the debugging and the array system is working as its displaying the numbers next to the array.

    The only thing that doesn't seem to be working is that the cellindex is not deleting the array item to stop it from repeating (it seems to have reduced amount of repeating but unfortunately it is still happening ). In debugging should the array item be deleted?

    This is what I've got so far.. I will re-read everything you posted and double check if I missed something as well.. Will post if I figure out issue!

  • No problem, happy to help.

    Okay, I think what is happening is that you actually are successfully deleting an array item, right before you jump to a new layout, but when the next layout starts, that new layout is running the "On start of layout" events (lines 17 & 18 in your image), and that is re-clearing and re-filling the array.

    I'll refer to the process of clearing and then filling the array as "initializing" the array.

    You'll need a way of initializing the array only once during the whole game.

    Two solutions come to mind.

    Solution 1: You could initialize the array on a unique layout that only runs once, like the title screen of the game.

    Solution 2: You could keep the initialization on start of layout, (the way you have it now), and add a global variable to disable initialization after the first time the array is initialized.

    Solution 2 - explained:

    To disable initialization after the first time the array gets initialized, you can create a global number variable "gb_initLayoutArray", with a starting value of 1.

    As the last step of the initialization process, set "gb_initLayoutArray" to 0.

    Finally, in the "On start of layout" events, add the condition, "gb_initLayoutArray" = 1.

    Now those "On start of layout" events should only run once.

    And if you ever need to initialize the array again later, just set the "gb_initLayoutArray" back to 1, and on the next layout you'll restart with a full "deck" of layout cards in your array again.

    (The "gb_" in the variable name is just my way of indicating that a variable is global "g", and should be treated like a Boolean "b". It doesn't mean anything special to Construct.)

    Let me know if that fixes it.

  • YAY!!!! Works perfectly!! Thank you sooooo much!

    Just checked the Debugging and it removes them as they are completed! This is so epic!

    Thanks for all your help! I am beyond greatful!

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