So, I'm working on a match-3 game similar to Ironcast (in concept, it's just seeing if I can). I've finally got the board to generate properly, and to place down random gems. Problem is, it's always generating the same placement, as though it were seeded (which it isn't, as far as I know).

Here's the code that directly generates the randomness (scr_generate_gem).

var insert = irandom_range(1, 4);//randomizing the gem inserted
var gem_insert;

        switch (insert)
        case 1: gem_insert = obj_Food;
        case 2: gem_insert = obj_Fuel;
        case 3: gem_insert = obj_Parts;
        case 4: gem_insert = obj_Meds;
        default: gem_insert = obj_Parent;

return gem_insert;

And here is where it's used.

//hardcoded height and width of the board. could change later
Large_Width = 6;
Large_Height = 6;

var i = Large_Width-1; //5, at the moment
var jreset = Large_Height-1; //5. Used to keep a reference to when j 
//needs to be reset to maximum, so the board fills out.
var j = jreset;

repeat(Large_Width) //repeat 6 times; i goes from 5 to 0 through repeats
    repeat(Large_Height) //repeat 6 times; j goes from 5 to 0 through repeats
    //ends up repeating this repeat 6 times, because of the above Repeat, making 36 in total
        //initialize the board by generating the objects
        BoardGems[i, j]  = instance_create((i-1)*36, (j-1)*36, scr_generate_gem()); //creates an object, and places it here
        j -= 1;//decrement j so we aren't overwriting the last object created.
    j = jreset;//resets j 
    i -= 1;//decrements i to make a new column
  • \$\begingroup\$ You can replace the code of scr_generate_gem with this: return choose(obj_Food, obj_Fuel, obj_Parts, obj_Meds); \$\endgroup\$
    – Dmi7ry
    Jul 10, 2017 at 7:12

1 Answer 1


Please read the documentation https://docs.yoyogames.com/source/dadiospice/002_reference/maths/real%20valued%20functions/randomize.html

Game maker is really well documented. So you would do yourself a favor by starting to use it. You do not even need internett, it is already in GM. The hot key for it is f1.

When you use the randomize function game maker will start to make random seeds. The default is set to not generate random seeds to make it easier for bugtesting during development. I would recommend having the randomize function in a object all by itself that deletes itself after having run. This way it will not take up any space and will only run once.

  • \$\begingroup\$ This answer would be even better if it included a brief summary of the insight you hope the user will glean from the documentation link (ie. that calling randomize() seeds the random number generator with a new value that will vary each time the game is run). \$\endgroup\$
    – DMGregory
    Jul 9, 2017 at 10:35
  • \$\begingroup\$ ok, what you meant was that gamemaker defaults to having the same seed for each run, and that randomize() changes that seed to a random one. \$\endgroup\$ Jul 9, 2017 at 13:03
  • \$\begingroup\$ Yes. That is what i meant. \$\endgroup\$ Jul 9, 2017 at 13:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .