Gamedev Grievances #28: Random Seeds for Edgy Teens

Hello, everyone! It’s been a tough couple of weeks for me gamedev-wise, due to several gamedev-related problems I’ve been grappling with. Most of those problems weren’t new issues, but old ones which all came back to bite me at roughly the same time.

One of those issues was with my save file system and dealing with random seeds in Ambience. Without further ado, let’s get this rant started – I mean, let’s take a look…

Random Seeds

In typical roguelike fashion, Ambience saves the game at the start of each area you access, whether it be a dungeon floor, boss room, or campsite. Once you move on from somewhere, there’s no turning back. The way Ambience does this for randomly generated dungeons is by saving the random seed used at the start of each area, and loading that seed again when you load the game.

A random seed is a (usually) big integer which GameMaker: Studio uses to determine the outcome of random events. So if you set the seed to a particular value at a particular time, then the same outcome of events will transpire every time. That also goes for dungeon generation, item placement, and so forth. So, loading a saved random seed at the start of a dungeon floor allows the game to recreate the entire dungeon from a single number.

The Edgy Part

As simple as this sounds, however, I’ve had more problems with this system than I’d like to admit. In the past I’ve had problems with GM:S loading the wrong seed due to the way it stores and outputs random seeds. As it turns out, GM:S saves seeds internally in the range [-x,x), but outputs them in the range [0,2x), which took a long time (and a big headache) to finally work out.

More recently, however, my problems have been specifically with loading the first floor of a dungeon. As far as I could tell, the problem was due to the sequence of events upon starting a dungeon in-game, which differed from the sequence of events when loading the game.

Say the player decides to enter a dungeon from somewhere else in-game. The game logic goes pretty much like this:

  • Set the dungeon number in a variable (for random generation)
  • Go to the dungeon room, and generate the random dungeon
  • Make a pretty announcement box telling you the dungeon and floor
  • Set the dungeon floor number to 1, if it isn’t already
  • Save the game (including the random seed)
  • Finally, fade out the announcement box and show the dungeon!

So far, so good. But what if I quit the game and load it again? This time the order of events is:

  • Load all variables (including the dungeon floor, which equals 1 since we’re on the first floor)
  • Go to the dungeon room, and generate the random dungeon
  • Show the pretty announcement box
  • Don’t bother saving the game or changing the floor number (since we’re loading the game)
  • Fade out the announcement box.

Here’s the problem. Notice that when the generate the random dungeon (and make use of the random seed), we’re not in exactly the same “state” each time.

  • When we’re going to the dungeon from an in-game location, the dungeon floor is set to zero (a placeholder value). We then change that to 1 (the first floor), but only after we’ve already generated the dungeon.
  • When we’re loading the game, the game loads the saved dungeon floor first, and then uses that along with the random seed to generate the dungeon.

As hard as it was to pick that up, solving the problem was easy. I just made sure that the dungeon floor was correct (and hence, all variables were the right values) each time before generating the dungeon layout.


Other “gamedev greivances” I’ve been grappling with lately have included computer 100% disk-usage issues (Windows can be such a pain!) and, once again, line of sight issues with dynamic terrain (as I mentioned in an earlier post). I am definitely still making progress though! I also made a new boss intro which I thought turned out fairly nicely:



Leave a Reply