I need to spawn just one building

Discussion in 'Programming' started by Mars, Apr 17, 2019 at 8:18 AM.

  1. Mars

    Mars Member

    Joined:
    Wednesday
    Posts:
    1
    I tried reusing the code from an enemy spawner to spawn the building that you need to reach to win the game when you reach a certain score, but it doesn't stop after one has spawned and it just spawns endlessly.
    here's the code i used:
    if (thescore > 100) instance_create_layer(random(room_width),random(room_height), "enemy_layer", obj_castle)

    how do i make it spawn just one castle instead of a whole bunch of them?

    Also would apreciate if anyone told me how to make text appear on the screen after you reach the score, maybe something like "the castle has been revealed, go find it.

    Any help is apreciated
     
  2. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    392
    On approach is to use a flag.
    Set it to false at game start:
    Code:
    global.has_spawned=false;
    Then use this in your conditional:
    Code:
    if (thescore > 100) && global.has_spawned==false
    {
    instance_create_layer(random(room_width),random(room_height), "enemy_layer", obj_castle);
    global.has_spawned=true;
    }
     
  3. marasovec

    marasovec Member

    Joined:
    Sep 15, 2016
    Posts:
    248
    Code:
    if thescore > 100 and !instance_exists(obj_castle) instance_create(x, y, obj_castle);
    
     
    Last edited: Apr 17, 2019 at 2:03 PM

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