GMS 2 Random Spawn

Discussion in 'Programming' started by SioNisti, Sep 14, 2018 at 4:01 PM.

  1. SioNisti

    SioNisti Member

    Joined:
    Aug 7, 2018
    Posts:
    21
    id want to spawn an object from 7 different ones on random on a specific spot
    Thanks for the help
     
  2. Vikom

    Vikom Member

    Joined:
    Jun 21, 2016
    Posts:
    92
    choose(object1, object2, ... , object16) chooses randomly one of up to 16 objects
    irandom_range(10, 100) chooses a random number between 10 and 100

    so

    Code:
    instance_create(
    irandom_range(0, room_width),
    irandom_range(0, room_height),
    choose(enemy1, enemy2, enemy3)
    );
    Spawns one of three enemies on a random location anywhere within the room.
     
  3. SioNisti

    SioNisti Member

    Joined:
    Aug 7, 2018
    Posts:
    21
    instance_create is shown in blue and gives me error when i try to run the game
     
  4. Vikom

    Vikom Member

    Joined:
    Jun 21, 2016
    Posts:
    92
    screenshot?
     
  5. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    379
    ...Can you not figure out that instance_create needs to be instance_create_layer? Look in the manual instead of coming to the forums for things like that. My guess would be that Vikom is used to GMS1.4's coding conventions while you are using GMS2.
     
  6. SioNisti

    SioNisti Member

    Joined:
    Aug 7, 2018
    Posts:
    21
  7. SioNisti

    SioNisti Member

    Joined:
    Aug 7, 2018
    Posts:
    21
    im new at this sorry
     
  8. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    379
    I don't mean to be harsh, sorry, I just mean, use a little bit of initiative and make sure you are referencing the manual when you're coding. I literally don't go a single coding session without opening the manual and I usually just have it open all the time. That way whenever I misword a function or something like that, it takes me two seconds of searching the manual to find out what I did wrong. Good luck on your coding =)
     
  9. Vikom

    Vikom Member

    Joined:
    Jun 21, 2016
    Posts:
    92
    Damn, GMS2 has some coding differences?
    That's another reason why I don't want it.

    Yes, it's always good to use the manual.
     
  10. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    379
    Eh, I was very much like that. Held off until about 2 weeks ago and now I regret not swapping over earlier. Doesn't take long at all to catch up to speed, I think I literally spent a single night bumming around in the new IDE before I started to feel confident in it, so not much time investment at all.
     
  11. SioNisti

    SioNisti Member

    Joined:
    Aug 7, 2018
    Posts:
    21
    Well i still cant do it ;_;
     
  12. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    379
    Can you english the question better sorry? I don't understand what you're trying to do.
     
  13. SioNisti

    SioNisti Member

    Joined:
    Aug 7, 2018
    Posts:
    21
    make one of seven objects spawn
    but the object to spawn is random
     
  14. SioNisti

    SioNisti Member

    Joined:
    Aug 7, 2018
    Posts:
    21
    Like how tetris on nes decides what piece to give to you
    it has a list of pieces
    it spawns 1 of them on random
     
  15. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    379
    It was posted earlier by Vikom, but:
    Code:
    instance_create_layer(x_position,y_position,"Instances",choose(object_1,object_2,object_3,object_4,object_5,object_6,object_7));
    choose() is a function that will randomly choose between the arguments you give it, this can be a number (i.e. choose(1,3,4,10)) or a string (choose("string 1","string 2")) or, in this particular case, it can choose between object identifiers (choose(object_1,object_2,etc)).
     
  16. SioNisti

    SioNisti Member

    Joined:
    Aug 7, 2018
    Posts:
    21
    Thanks ^-^ and sorry :D
     
    RefresherTowel likes this.

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