Windows Room Start - irandom giving same variable

Discussion in 'Programming' started by Bazzawill, Dec 5, 2018.

  1. Bazzawill

    Bazzawill Member

    Joined:
    Dec 5, 2018
    Posts:
    2
    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);
        }
    }
    
     
  2. Satori

    Satori Member

    Joined:
    Oct 26, 2018
    Posts:
    33
    Use randomize();
     
    Bazzawill likes this.
  3. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    604
    Bazzawill likes this.
  4. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    3,405
    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
     
    Bazzawill likes this.
  5. Bazzawill

    Bazzawill Member

    Joined:
    Dec 5, 2018
    Posts:
    2
    Thanks :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice