Using Seed Variables

This Plugin uses a seedable randum number generator to generate worlds. This way dungeons can be created the same way when a player re-enters them – if you wish. This article shows some examples:

Randomize everytime the Player enters

If you want the dungeon to be randomly generated everytime the player enters it, uses this command right before you call the generator.

var seed = Math.Floor(Math.random() * 100);
$dungeonGenerator.setSeed(seed);

Use Seed variables

A more natural way to generate dungeons would be, that when a player leaves a dungeon to go to the world map, and then re-enters it, it still looks the same. For my own game project I use this strategy: When a new game is started, a globally seed variable is randomly chosen once and then stored for this save slot. When the player leaves the world map to visit a dungeon, then his X and Y coordinates are also used to feed the generator. While the player is inside a dungeon, he cannot save his progress. Storing this variables is done by using standard event commands as this is much more convenient.

Storing the global Seed

Once the game starts, we call a “Change Variable Operation” to set a global variable called “Seed” with a random number.

Storing the X and Y Coordinates

As soon as the player wants to enter a dungeon from the world map, we memorize his position and store his X and Y coordinates.

Feeding the Generator and Finalize

Get a new seed variable by using this command:

var seed = $gameVariables.value(1) * $gameVariables.value(2) * $gameVariables.value(3) % 100;
$dungeonGenerator.setSeed(seed);

While the numbers 1, 2 and 3 stand for ist respective ID in the global variables. Ensure to set them correctly. Feel free to add more variables or leave some out if you wish.

This is part of the command I currently use for my own game project.
PS: I store some more variables (X, Y and Progress) but I only use the global seed.

Leave a comment

Your email address will not be published. Required fields are marked *