Windows Room Start - irandom giving same variable

B

Bazzawill

Guest
Hi there,
I am using the following code to randomly generate a power up blocks in my game however every time I run my game the blocks are in the same spot
Code:
if (room == rGame)
{
    repeat(2)
    {
        var xx = irandom(room_width);
        var yy = irandom(room_height);
        instance_create_layer(xx,yy,"Instances",oPower);
    }
}
 

rIKmAN

Member
Hi there,
I am using the following code to randomly generate a power up blocks in my game however every time I run my game the blocks are in the same spot
Code:
if (room == rGame)
{
    repeat(2)
    {
        var xx = irandom(room_width);
        var yy = irandom(room_height);
        instance_create_layer(xx,yy,"Instances",oPower);
    }
}
This is intended behaviour.

If you want real random values each time you run you need to use the randomize() function once at the start of your game.

https://docs.yoyogames.com/source/dadiospice/002_reference/maths/real valued functions/randomize.html

edit: ninja’d
 
Top