Legacy GM [Solved] Help!!!!!!!!! Trying to spawn different bosses with the same object according to the room

R

RetroCop

Guest
my code

if (instance_number(obj_boss1)>0) exit;
if (instance_number(obj_boss2)>0) exit;

if (room_exists(lv_1)) instance_create(x+500,y+350,obj_boss1)
if (room_exists(lv_2)) instance_create(x+500,y+350,obj_boss2)

the problem is that both spawn in each room instead of boss1 spawning in lv_1 and boss2 in level_2
 

YoSniper

Member
Both spawn because both rooms exist. Instead, do this:

Code:
var boss_obj;
if room == lv_1 {
    boss_obj = obj_boss1;
} else if room == lv_2 {
    boss_obj = obj_boss2;
}

instance_create(x + 500, y + 350, boss_obj);
 

Schwee

Member
I think room_exists is returning whether or not the room exists in your game. Maybe go off room_get_name or possibly even just (if room = lv_1) but I'm not sure so you'd have to test.
 

Coded Games

Member
You're making it more complicated than it needs to be.

if (room == lv_1) instance_create(x+500,y+350,obj_boss1)
if (room == lv_2) instance_create(x+500,y+350,obj_boss2)
 
R

RetroCop

Guest
Thanks probably should've done more research on room_exists
 
Top