• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Random Spawn

S

SioNisti

Guest
id want to spawn an object from 7 different ones on random on a specific spot
Thanks for the help
 
V

Vikom

Guest
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.
 
S

SioNisti

Guest
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.
instance_create is shown in blue and gives me error when i try to run the game
 
...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.
 
S

SioNisti

Guest
...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.
im new at this sorry
 
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 =)
 
V

Vikom

Guest
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.
 
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.
 
S

SioNisti

Guest
make one of seven objects spawn
but the object to spawn is random
 
S

SioNisti

Guest
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
 
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)).
 
Top