GameMaker Simple yet complex

Z

Zynpex

Guest
So, I have a basic scoring system, in the space shooter I'm making, when the bullet hits the enemy, if the hp is = or less than 0, the score is adjusted for the player, based on the score_value Var I set. I set a script for this, in the script is the following. The script is for Collision event with the player bullets to an enemy.


instance_destroy();

other.hp -= 1;

if (other.hp <= 0) {

score += other.score_value;

}

this works great, the only problem is the ship for the player shoots 2 bullets and if both bullets meet the target at the same time, and if it is destroyed then the player is granted double the points.
 
H

Homunculus

Guest
Since the enemy already has some logic related to its destruction, can’t you increase the score inside that logic, instead of doing it in the bullet? Doing it this way should guarantee that the points are added only once, before destruction.
 

samspade

Member
I have a similar project and have set it up like this:
  • Things that deal damage, deal damage regardless of hp, they don't even check.
  • Things with hp do one hp <= 0 check in the end step event.
Code:
if (hp <= 0) {
    global.points += 1;
    instance_destroy();
}
 
Z

Zynpex

Guest
Thanks for the tip! After reading that, I decided to experiment a little. In the destroy event for the Parent Obj for my enemy ships I used the following.

if (object_index != o_player_ship) {
score += other.score_value
}
 
H

Homunculus

Guest
Does this even work? other has no meaning unless you are in a collision event or in a with statement.
 
Z

Zynpex

Guest
Yes this works. And the other.score_value was for a collision, thanks for pointing that out, I'm sure it will run just fine without the other, and i have just tested yes it works the same with and without.
 
Top