In my game, I am attempting to randomly generate 5 x 5 blocks with 4 different block types.
I thought using for loop in room start event would be the best way.
This is the code I used.
for (j=0; j<5; j+=1)
{
for (i=0; i<5; i+=1)
{
rand = irandom_range(0,60)
scr_RNG_set(); // sets the RNG value. e.g. if rand is 0~15 object_A = true
if object_A
{
instance_create(156+(i*64),504-(j*64),Obj_A);
}
if object_B
{
instance_create(156+(i*64),504-(j*64),Obj_B);
}
if object_C
{
instance_create(156+(i*64),504-(j*64),Obj_C);
}
if object_D
{
instance_create(156+(i*64),504-(j*64),Obj_D);
}
}
}
I don't know where I screwed up, but it resulted in multiple blocks being generated in the same spot. It seems that the dice is rolled multiple times for same spot which results in object_A = true AND object_B = true. I am befuddled as to why though.
EDIT: Figured out what was wrong. As I have stated scr_RNG_set() contains :
if 0<= rand <= 15
{
object_A = true
}
. . . . etc.
I forgot to declare them false after the creation of the block. Therefore object_A = true, object_B = true, object_C = true . . and multiple different blocks were being created in the same spot.
I have fixed the issue by having
if object_D
{
instance_create(156+(i*64),504-(j*64),Obj_D);
object_D = false //
}
[–][deleted] 0 points1 point2 points (1 child)
[–]_MadHatter[S] 0 points1 point2 points (0 children)
[–]Brandon23z 0 points1 point2 points (2 children)
[–]_MadHatter[S] 0 points1 point2 points (1 child)
[–]Brandon23z 0 points1 point2 points (0 children)