How do I...implement a randomized, then permanent combination in my game?

Have you guys ever seen something in games where like...the combination for something is randomized each game, but once you load the game, it remains that combination for the rest of that particular game?

For example, let's say there's a 4-digit combination lock that has a randomized combination for each play through. Once you begin a play through, that combination is set and stone for the rest of that particular game. (This way, players don't just remember codes outside of the game world, and try to quick-run it).


I want to implement something like this in my game. In my game, the player can find 4 objects in a particular location. But when you need to use those objects at their destination, the order they need to use those objects will change for every play through.

How would I go about coding such a thing?

Thank you! : )
Make an event on the map where your player starts.
Let it be a parallel process.
Setup the variables with their random values there
Turn a self-switch on.
Make a new page which requires that self-switch to be on as a condition.

Personally I like having the player start at a blank map where I setup all I like before transfering the player to their normal starting position.
What Zeriab said is correct, if a bit overly specific. Simply, any value you set variables or switches to gets saved in that playthrough until you change them. This doesn't have to be in its own event or a separate map (although those are fine organizational ideas) - wherever you have the event that gives the items to the player can randomly determine their order and store it in variables. My only question is...
Once you begin a play through, that combination is set and stone for the rest of that particular game. (This way, players don't just remember codes outside of the game world, and try to quick-run it).
Why is this a concern? Is your game really diverse enough that a person is going to play it multiple times? (this isn't a knock on you, most video games are not)

And if they do, why is it important that the order of these items be potentially different? Do you have other elements of the story that change every play? If the idea of replaying more quickly is somehow troubling to you, do you believe that a given player will, for example, read every line of dialogue as carefully the second time they play through the game?
What Zeriab said is correct, if a bit overly specific. Simply, any value you set variables or switches to gets saved in that playthrough until you change them. This doesn't have to be in its own event or a separate map (although those are fine organizational ideas) - wherever you have the event that gives the items to the player can randomly determine their order and store it in variables. My only question is...

Why is this a concern? Is your game really diverse enough that a person is going to play it multiple times? (this isn't a knock on you, most video games are not)

And if they do, why is it important that the order of these items be potentially different? Do you have other elements of the story that change every play? If the idea of replaying more quickly is somehow troubling to you, do you believe that a given player will, for example, read every line of dialogue as carefully the second time they play through the game?

Ahh I see, I will go ahead and try to work with Zeriab's suggestion!


As for your question, my game is puzzle based. There aren't really any "battles" or enemies to fight. It's all about trying to solve puzzles without getting injured/killed by obstacles along the way. So of course, I need to put most of my "dungeon thinking" into puzzle solving.
The reason I want to add a few things like scenarios of these randomized permutations is because I don't want there to be 1 and only 1 direct solution to some of the more important and major puzzles.

Here's how I picture the issue:
Spoiler: (Long read)
Imagine someone decides to play my game, and broadcast it live on a video like twitch/youtube or something. (I don't think it is likely of course, but you never know). If the audience watching that person decides "Hey, I want to play that game too!", then they should not just follow whatever the broadcaster did in their game.

Some of the puzzles really require you to think carefully, and I want players to try and figure it out on their own without directly following someone else's footsteps or some direct walkthrough. Everything you need is going to be there, but it won't always be direct.
This could mean...locations of certain key elements change, or the way you need to order something (like I want in this help thread) could be subject to change. There could be scenarios where room X is necessary and room Y is not necessary, but for someone else's game, they had to go through room Y and could ignore room X. The list goes on.

Do these things affect the game's story elements? No, they do not. But there are a couple of different endings and small things you can earn based on what you "finish" in the game. If the player meets certain conditions that they earn from doing certain sidequests/side-dungeons, they are granted nice award(s) when they reach the end point.

There are limits to RPG Maker of course, but I really want to experiment around and see if players are capable of solving puzzles that aren't too difficult, but not hand-holdy either.

As for repeat playthroughs?
If the player wishes to 100% the game, then they can always go back to the previous save and load it in. So no, I do not expect people to "replay" the game, but rather see if they can "solve" and "get" everything it had to offer. I know I did not specify this earlier, but in this game, you can do anything you want in any order. You could jump straight into a few things (side dungeons, sidequests, etc.), but you only have 1 main quest that's "required" of you to "beat" the game.
You mentioned re-reading dialogue in the event of a 2nd playthrough. While there is some dialogue, there isn't a whole lot of it. And certainly you don't need to experience most of it if you don't want to, but really, there isn't much dialogue to go through.


Anyway, to answer your main question, my main concern is the idea of people being able to do 1 and only 1 thing for every single puzzle. If that is the case, then the game becomes a lot more boring if it's getting shared. If people see others playing it, and constantly share around, then it's only a matter of time before people start memorizing everything rather than trying to figure it out on their own. I really don't want that. How fun is a game when you need to solve a 4-digit pass code when you already know the solution to it because you saw someone else play through it, or you looked it up online? And since puzzle solving is the core focus of the game, I want to avoid that. Sure, there are some things that won't change of course, but I do wish to have some of the more "major" puzzles switched around so it's not so direct.


Haha, sorry if I went on for a little bit. I have been developing this personal project for months and I rarely get asked about it. Feels nice to talk about it with someone who seems genuinely curious. Does that answer your series of questions? Any thoughts/critiques maybe? I always love feedback.
As I understand it, he wants the player not to be able to memorize the code or order of "keys" in case he restarts the game or informs another player.
In this case, it is possible to do this with events only.
But if it is an event to place 4 items on 4 platforms or a chest with 4 keys it will be very big.
Therefore, it would be ideal to use Javascript to randomize the possibilities:
JavaScript:
function shuffle(a) {
    var j, x, i;
    for (i = a.length - 1; i > 0; i--) {
        j = Math.floor(Math.random() * (i + 1));
        x = a[i];
        a[i] = a[j];
        a[j] = x;
    }
    return a;
}
shuffle(["key-A","key-B","key-C","key-D"])

Reference:
As I understand it, he wants the player not to be able to memorize the code or order of "keys" in case he restarts the game or informs another player.
In this case, it is possible to do this with events only.
But if it is an event to place 4 items on 4 platforms or a chest with 4 keys it will be very big.
Therefore, it would be ideal to use Javascript to randomize the possibilities:
Code:
function shuffle(a) {
    var j, x, i;
    for (i = a.length - 1; i > 0; i--) {
        j = Math.floor(Math.random() * (i + 1));
        x = a[i];
        a[i] = a[j];
        a[j] = x;
    }
    return a;
}
shuffle(["key-A","key-B","key-C","key-D"])

Reference:

Hahah, yeah. This right here. A permutation of 4 places and 4 decrementing choices is 4 x 3 x 2 which is 24 possibilities...that's a lot of code, haha. Thanks for giving me this for-loop though!
It is possible to do with events as well:
Code:
◆Control Variables:#0021 Key-A = Random 1..4
◆Loop
   ◆Control Variables:#0022 Key-B = Random 1..4
   ◆Conditional Branch: Key-B ≠ Key-A
      ◆Break Loop
   :End
   ◆
:End
◆Loop
   ◆Control Variables:#0023 Key-C = Random 1..4
   ◆Conditional Branch: Key-C ≠ Key-A
      ◆Loop
         ◆Conditional Branch: Key-C ≠ Key-B
            ◆Break Loop
         :End
      ◆
      :End
      ◆Break Loop
      ◆
   :End
   ◆
:End
◆Loop
   ◆Control Variables:#0020 Key-D = Random 1..4
   ◆Conditional Branch: Key-D ≠ Key-A
      ◆Loop
         ◆Conditional Branch: Key-D ≠ Key-B
            ◆Loop
               ◆Conditional Branch: Key-D ≠ Key-C
                  ◆Break Loop
               :End
            ◆
            ◆Break Loop
         :End
      ◆
      :End
   ◆
   :End
   ◆
:End
Sorry, I'm not at home, it may not work as it should.

If you want to transform the four variables into a single one, you can do it this way:
Code:
◆Control Variables:#0021 Key-A * 1000
◆Control Variables:#0022 Key-B * 100
◆Control Variables:#0023 Key-C * 10
◆Control Variables:#0020 Key-Password + Var Key-A
◆Control Variables:#0020 Key-Password + Var Key-B
◆Control Variables:#0020 Key-Password + Var Key-C
◆Control Variables:#0020 Key-Password + Var Key-D
As I understand it, he wants the player not to be able to memorize the code or order of "keys" in case he restarts the game or informs another player.
I understood. My question was from a game design perspective - why?
Case one: a person replays the game. Unless you somehow can make the entire process of the puzzle different, he's going to remember how this puzzle works. In that case, having the actual answer randomized is of negligent importance, he's already figured out how to do it.

Case two: another person is playing and wants the answer. Why would you want to interfere with that? Either the person finds the puzzle too hard and needs help, or they're a person who just plays games with a walkthrough to enjoy the experience and story. In either case, why would it matter to you, the designer, to stop them from being able to do that?

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-implement-a-randomized-then-permanent-combination-in-my-game.135810/