Choosing a random layout.

0 favourites
  • 11 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I am making a game where layouts are chosen randomly from a pool of 250 layouts. When the game randomly chooses a layout, the game should not send the player to any menu layouts, or repeat previously chosen layouts. What's the easiest way to do what I want to do? I really don't want to create >250 events based off a randomly chosen variable.

  • nextroom as global variable

    name your layouts 1,2,3, etc

    Make a function: chooselayout

    on function

    set nextroom to

    random(int(1,250))

    Go to layout nextroom

  • Very helpful, but I ran into an error: i.imgur.com/xKxm3h0.png

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Very helpful, but I ran into an error: i.imgur.com/xKxm3h0.png

    You must have your global value set as text, set it as a number. You'll also have to set your variable as a string in the go to layout by name event. Use this:

    str(nextlevel)

  • I used <font face="Times New Roman, Times, serif">int(random(1,250))</font> and it accepted. I will report back with results.

  • I used <font face="Times New Roman, Times, serif">int(random(1,250))</font> and it accepted. I will report back with results.

    Sounds good, just curious, why do you have 250 layouts?

  • The player must get through 100 different rooms per game, and having a pool of 250 allows for many unique playthroughs.

  • The player must get through 100 different rooms per game, and having a pool of 250 allows for many unique playthroughs.

    Like a dungeon crawler?

  • it is easier to use round than int. so basicly round(random(1,250)) . To save an event just use

    onEvent -> go to layout "room"&round(random(1,250)).

    Keep a global variable for the amount of rooms done.

  • Hi,

    I think you might want to use some shuffling or helper storage, to avoid getting into the same room twice. Two ways (there are certainly more):

    1) create array of size 250

    2) fill it with consecutive integers

    3) shuffle random pairs of a hundred or more times

    4) make the player go from room to room, according to the (shuffled) order of elements in your array.

    Way #2:

    1- draw random integer as in examples you've seen above

    2- if integer is already in the helper container (#3 below), repeat drawing

    3- store the number in a helper array/string etc

    4- proceed to the selected layout

    Hope it helps,

    Greg

  • mrPeanut

    CJK

    Thanks for the suggestions, I will report back once I try them out.

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