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;
break;
case 2: gem_insert = obj_Fuel;
break;
case 3: gem_insert = obj_Parts;
break;
case 4: gem_insert = obj_Meds;
break;
default: gem_insert = obj_Parent;
break;
}
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
}
scr_generate_gem
with this:return choose(obj_Food, obj_Fuel, obj_Parts, obj_Meds);
\$\endgroup\$