instancegame-makercreateinstance

Game Maker - Create Instance When Health Is 0


I have five objects: obj_Boss, obj_bossHealth, obj_GameOver, obj_BtnOK, and obj_rec2.

This is what I want. When obj_Boss has no more health, obj_GameOver and obj_BtnOK will appear.

This is my first method:

In obj_bossHealth, I have these events:

Create Event: set var global.bossHealth to 100

Draw Event: draw_healthbar

In obj_Boss, I have these events:

Collision with obj_rec2: set var global.bossHealth relative to -1.5; destroy the instance (other)

No More Health: create instance of obj_GameOver; create instance of obj_BtnOK

This is my second method:

In obj_bossHealth, I have these events:

Create Event: set var global.bossHealth to 100

Draw Event: draw_healthbar

Step Event: if global.bossHealth is equal to 0 then create instance of obj_GameOver and create instance of obj_BtnOK

In obj_Boss, I have these events:

Collision with obj_rec2: set var global.bossHealth relative to -1.5; destroy the instance (other)

The result of both methods:

obj_GameOver and obj_BtnOK won't appear. How can I fix this? Please explain your answer. Thanks.

I add some images: method1 method2


Solution

  • I've already known my mistake.

    I can't use my first method. Because I make a variable global.bossHealth and reduce that variable by 1.5 every time it collides. But, I put event No More Health, which is still at value 100.

    I use my second method. In my question, I reduce the global.bossHealth by 1.5. But, 100 is not divisible by 1.5. So, the conditions if global.bossHealth is equal to 0 will never be True. I change the actions in Step Event. I change if global.bossHealth is equal to 0 into if global.bossHealth is less than or equal to 0. Which less than 0 can be True.