Random Level Selection?

It’s been over 20 years since I did any programming so I’m more than a little rusty and I need a bit of guidance please if any of you have the time.

I’m working on a VR game that’s going to have procedurally generated levels and I’m planning on building them NOT at runtime but pre-made beforehand.

I’m also looking at creating 5 different maps for each level. So I’m going to have 5 playable levels during each game and choose 1 out of 5 possible maps for each of the 5 levels. I also want to make sure that each time someone plays they get a different level to play in.

I’m probably not explaining this very well lol

So basically a new player starts a game:

Map (random n) out of 5 possible Maps (for example) is loaded for Level 1.

When that level is finished Map (random n) is loaded for level 2

All the way until level 5, the final level.

And once the game is finished by the player any new games will work as above but instead of choosing from 5 maps for each level the game will choose from 4 because one has already been played. And the next time from 3 and so on.

I’m just wondering what the best way of organising this will be?

I haven’t much of an idea where to start tbh. I’m guessing that the best bet would be 5 arrays Level1(5), Level2(5), Level3(5), Level4(5) and Level5(5).

Choose a random number for Level1(n) and write that number to a variable, and as soon as that has been done replace that number in Level1(n) with a null value? Have that in a For loop (does the UE have For loops?) until the 5 levels have been selected.

Then when a new game is selected using the same save slot there’ll only be 4 maps to choose from.

Or am I completely on the wrong track?

I’m just having problems getting this all sorted out in my head, like I said I’m VERY rusty!!! :eek::stuck_out_tongue:

Many ways to do it, consider the following:

  • have an array with all map names and *Shuffle *it (it now contains elements in random order)
  • save the shuffled array to a save game object
  • Load the map at element 0
  • once a level is finished, remove element 0, save the array
  • rinse & repeat the 2 previous steps

or, if you do not want to remove array elements:

  • have the Game Instance keep track of an array with all map names and *shuffle *it, have it keep track of an int Variable as well
  • use that Var to *Get *and *Load *map at index Var from the Shuffled Array
  • add 1 to the Var once the level is finished and use the int value to Load map at index Var
  • you only need to save between game sessions

Brilliant, thanks for that! I’ll check those two methods out. Ta! :slight_smile:

Dear Everynone and thesnowdog,
I just stumbled upon your conversation and find it very useful for my own research paradigm.

I think the options given as an answer would perfectly fit, because I am trying to load levels randomly, with keeping track of them. Let’s say I have 5 different levels (conditions), and I want each of them to appear in a random order of 100 trials.

Everynone, could you please specify in your answer which blueprints you are refering to for each step (solution 2 looks easier to implement but I might be wrong).

I am digging this post from the archives, but maybe this could still be useful!
Anyways, thank you very much for your help, even as just this post in itself!

The Game Instance, which can handle Save Games at the same time.

I’ll try this then, thank you!