Gamemaker 8.1 Player obj dies for no reason.

C

Century

Guest
Ok, so I am working on a game for school (assessment) and it is on Gamemaker 8.1

For some reason when the enemy's health reaches 0, the player dies, not the enemy. I cannot see why this would happen. I can give extra information if you need, I really don't know why this is happening or what code is causing this.

Thanks.
 

YoSniper

Member
I don't have a lot of information, but I have some hunches:

The enemy's death (the way it is supposed to be) happens during a collision event with the player, and...

your use of the other keyword is wrong.

Please post your code to confirm, but this is the first thought that comes to me.
 
C

Century

Guest
it is gamemaker 8.1 so it is forced drag and drop. The enemy obj dies when it makes contact with the player's fireball and the player dies when it makes contact with the enemy's fireball. They are different objects with different code.

Is there to post code from there?
 

TheouAegis

Member
Just because it is GM 8.1 doesn't mean it's required to be drag and drop. All versions of game maker use gml. click on the object and then you will see a button that says "show info" or "object information". Click on that and then copy everything in the window that pops up.

We will need the player object info, the enemy object info, and the fireball object info. If you are using two distinct fireballs, we will need both fireballs.
 
C

Century

Guest
Information about object: obj_fireball
Sprite: spr_fireball
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Mask:
Collision Event with object obj_border:
kill all instances at relative position (0,0)
Collision Event with object obj_enemy_weapon:
kill all instances at relative position (0,0)

Information about object: obj_enemy_weapon
Sprite: spr_enemy_weapon
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Mask:
Collision Event with object obj_border:
kill all instances at relative position (0,0)

Information about object: obj_player_fight
Sprite: spr_player_back_station
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Mask:
Collision Event with object obj_border:
start moving in directions 000010000 with speed set to 0
Collision Event with object obj_enemy_weapon:
set the health relative to -10
Keyboard Event for A-key Key:
start moving in directions 000100000 with speed set to 5
Keyboard Event for D-key Key:
start moving in directions 000001000 with speed set to 5
Other Event: Room Start:
set the health to 100
Other Event: No More Health:
go to room rm_lose with transition effect Interlaced from top
Key Press Event for Key:
create instance of object obj_fireball at relative position (0,0) with speed 7 in direction 90
Key Release Event for A-key Key:
start moving in directions 000010000 with speed set to 0
Key Release Event for D-key Key:
start moving in directions 000010000 with speed set to 0

Information about object: obj_enemy_fight-2
Sprite: spr_enemy_front
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Mask:
Create Event:
set the health to 50
set Alarm 0 to 45
Alarm Event for alarm 0:
set Alarm 0 to 45
create instance of object obj_enemy_weapon at relative position (0,0) with speed 7 in direction 270
Collision Event with object obj_border:
bounce not precisely against solid objects
Collision Event with object obj_fireball:
set the health relative to -10
Other Event: Room Start:
start moving in directions 000101000 with speed set to 6
bounce not precisely against all objects
Other Event: No More Health:
sleep 1000 milliseconds; redrawing the screen: true
set the score relative to 500
go to room rm_level1-4 with transition effect Blend
 

TheouAegis

Member
Okay, there are quite a few issues here.

First off, you cannot use the variable health. it is a built-in, global variable. What this means is that your enemy and the player are both using the exact same health variable. So when the enemy dies, the player dies. You need to make your own variables.

Consequently, the No More Health event only applies to that global health variable. You're going to need to have instead code in the step event which checks if the custom health variable that you created for that particular instance, either the player or the enemy, is less than 1.

kill all instances at relative position (0,0)
I never used 8.1, I skipped over it from GM 8 to studio. But, this looks like you are using the wrong action, assuming that the correct action is still available. What you should be using is just a normal Destroy Instance action. the normal action has no arguments for you to fill in, you just throw it into your code and that's it. It looks like you are using an action such as Destroy At Position, which requires two arguments, x & y. Using the normal Destroy Instance action, you need to change the scope of it. If you look at the top of every drag-and-drop action, there is a set of radio buttons labeled self, other, and object. By default self is always checked. This means that the code action will apply to the instance that is calling that action. The other scope meanns that the code action will apply to the instance that you collide with when use inside of a collision event. Outside of a collision event, the other scope means nothing, but inside a collision event, it will apply to the instance that you are colliding with.

Now this will have a slight drawback which in most cases never amounts to much of anything and realistically shouldn't amount to much of anything, insofar as if a projectile hits multiple targets at the same time, only one target would be destroyed.

Another issue I may see in your code is it appears you are not destroying the fire ball after it hits a Target. this means a fireball could potentially deal damage multiple times to the same Target.
 
Top