[SOLVED] Seed Help

G

gamedev513

Guest
Hey guys,

I have a randomly generated dungeon that is created using different sprite indexes as a guide/blueprints that are different colors. Ive provided 2 generated levels (i.e. images below - every color is a different room that will have different things inside).

I'm trying to implement seed functionality similar to Minecraft or Binding of Isaac where a player can input a value and it will automatically return the same room setup every time. Note that the positions of the rooms/blueprints are static and do not change. I use arrays to store the sprite index values to be drawn and the amount of array indexes is based on the maximum value of blueprints/rooms allowed (how many rooms the level will have).

Hopefully someone can help me out?

Create event of obj_gen:
Code:
randomize();

// Determine level we are on
switch(argument[0])
{
    case 1: // Use Level 1 Blueprints
        
        // Randomize max blueprints allowed
        max_blueprint = irandom_range(7, 10);       
       for(i = 0; i < max_blueprint; i++)
       {
            blueprint_select = irandom(sprite_get_number(L1));
            blueprint_array[i] = blueprint_select;
        }
        
    break;
    
    default: break;
}
Draw event of obj_gen:
Code:
draw_set_alpha(1);

xx = room_width div 2;
yy = 0;

for(i = 0; i < max_blueprint; i++)
{
    draw_sprite(L1, blueprint_array[i], xx, yy);
    yy += 36;
}
 

Attachments

G

gamedev513

Guest
Game Maker Studio contains a function for this:
Code:
random_set_seed(value);
I was reading up on that function. Would I need to implement any sort of ds_list or grid? Not too familiar with seeding or their functions
 
V

VectorStudio

Guest
I was reading up on that function. Would I need to implement any sort of ds_list or grid? Not too familiar with seeding or their functions
I guess that random system in Game Maker works in the same way like in other programming languages which means that it's not really "random" but it's a algorithm that gives you numbers. You are using function randomize() to set different seed every time the game is executed. If you want to set your own seeds you have to add something that will ask a player for the seed value and than set the seed by function I wrote you.
 
G

gamedev513

Guest
The following did the trick:
Code:
randomize();
global.seed = get_string("Enter Seed:", "123");
random_set_seed(global.seed);
// All remaining code here...
global.seed = 0;
blueprint_array = 0;
 
Top