GameMaker: Studio

GameMaker: Studio

View Stats:
bae0nfluxx Aug 3, 2014 @ 6:38pm
Score added display
Hello!

I'm having a bit of trouble with a game I'm making. It's a simple Galaga type shooter, and I have most things working (score, lives, etc...), but am having trouble adding a feature.

Every time you kill an enemy, I want the score added to display where it was killed (for enemy1 it displays "+10" for a second where it was destroyed, for enemy2 it displays "+20" for a second where it was destroyed, etc...). I have programming experience, and have tried multiple things, but I'm also kind of new to Game Maker, and can't quite figure out how to add this feature.

Thanks for your time (:
< >
Showing 1-15 of 16 comments
Blind Aug 3, 2014 @ 6:49pm 
Create a score object that is created when an enemy is destroyed, have it float around as desired and then self destruct.

You can opt for an individual object for every possible score value, or you could use a custom font and have it as text that floats instead.
Thew Aug 3, 2014 @ 7:05pm 
Try something like this:

Create an object called "obj_score" or something similar.
// Create Event points = 0; counter = 0; // Draw Event draw_text(x, y, string(points)); // Step Event counter += 1; if (counter == 60) { instance_destroy(); }

Now in the code where your enemy object is destroyed:
score_number = instance_create(x, y, obj_score); with (score_number) { points = 10; // or however many points you want the enemy to be worth }
Daynar Aug 3, 2014 @ 7:12pm 
Originally posted by Thew:
Try something like this:

Create an object called "obj_score" or something similar.
// Create Event points = 0; counter = 0; // Draw Event draw_text(x, y, string(points)); // Step Event counter += 1; if (counter == 60) { instance_destroy(); }

Now in the code where your enemy object is destroyed:
score_number = instance_create(x, y, obj_score); with (score_number) { points = 10; // or however many points you want the enemy to be worth }
This works nicely. However, I'd highly suggest he use an alarm with room_speed*seconds to ensure it stays up as long as he wants.
Blind Aug 3, 2014 @ 7:14pm 
You can use a script for that, I like to use scripts as variable names just for the colour change sometimes.
bae0nfluxx Aug 3, 2014 @ 7:41pm 
I can't believe I didn't think of that! It works perfectly. I can't thank you guys enough for your help. (:
Thew Aug 3, 2014 @ 7:56pm 
Originally posted by Artoria:
I can't believe I didn't think of that! It works perfectly. I can't thank you guys enough for your help. (:
Glad to hear it. Good luck with your project!
bae0nfluxx Aug 5, 2014 @ 8:05am 
Hm, I'm afraid I've run into a bit of a problem involving this feature. If enemy 1 displays +10, and enemy 2 displays +20, if you kill them in quick succession, it changes enemy 1's display to +20 (or whatever enemy 2's is). I've been stuck on this for a little while now, and really don't know how to solve it.
Daynar Aug 5, 2014 @ 10:05am 
Originally posted by Artoria:
Hm, I'm afraid I've run into a bit of a problem involving this feature. If enemy 1 displays +10, and enemy 2 displays +20, if you kill them in quick succession, it changes enemy 1's display to +20 (or whatever enemy 2's is). I've been stuck on this for a little while now, and really don't know how to solve it.
This is likely a problem with the code:
score_number = instance_create(x, y, obj_score); with (score_number) { points = 10; // or however many points you want the enemy to be worth }
If you used the object id within the 'with()' part of the code it will loop through all objects with that id opposed to the one you just created.
score_number = instance_create(x, y, obj_score);
is very important. This saves the id of the instance you just created to a variable which you can later use to modify that instance specificly. You should be sure to use the variable holding the INSTANCE id within the with statement and I believe it should work, unless I misdiagnosed the problem entirely.
Last edited by Daynar; Aug 5, 2014 @ 10:07am
bae0nfluxx Aug 5, 2014 @ 1:13pm 
I fixed it! Thank you for your help :D My code ended up a little different from everyones suggestions, but with a combination of them all it fixed the problem.

obj_enemy Destroy event:

if (sprite_index == spr_enemy_1535)
{
score_number = instance_create(x,y,obj_added_score)
with(score_number)
{
mypoints = 1535;
}
}

And did that for every type of sprite enemy

Then my obj_added_score Draw event is just:

draw_text(x,y,"+"+string(mypoints));
Thew Aug 5, 2014 @ 2:08pm 
Yeah, Daynar hit the nail on the head there. It's an easy mistake to make, but a very important distinction -- the difference between an object and an object instance.

Also, you don't need to hard code the number into "mypoints." You could use a variable or calculation. That way you could have a score multiplier tied to an alarm or something similar. Of course, we're only looking at a very small part of your code, so I'm not sure what will work for your specific project.
bae0nfluxx Aug 5, 2014 @ 3:10pm 
Definitely...glad I know that now!

Yeah, I have 20 different enemies all with different point values, so it worked best to hard code them in (:
Just Jory Sep 8, 2018 @ 8:20am 
Originally posted by Daynar:
Originally posted by Thew:
Try something like this:

Create an object called "obj_score" or something similar.
// Create Event points = 0; counter = 0; // Draw Event draw_text(x, y, string(points)); // Step Event counter += 1; if (counter == 60) { instance_destroy(); }

Now in the code where your enemy object is destroyed:
score_number = instance_create(x, y, obj_score); with (score_number) { points = 10; // or however many points you want the enemy to be worth }
This works nicely. However, I'd highly suggest he use an alarm with room_speed*seconds to ensure it stays up as long as he wants.
Just Jory Sep 8, 2018 @ 8:20am 
Originally posted by Thew:
Try something like this:

Create an object called "obj_score" or something similar.
// Create Event points = 0; counter = 0; // Draw Event draw_text(x, y, string(points)); // Step Event counter += 1; if (counter == 60) { instance_destroy(); }

Now in the code where your enemy object is destroyed:
score_number = instance_create(x, y, obj_score); with (score_number) { points = 10; // or however many points you want the enemy to be worth }
Just Jory Sep 8, 2018 @ 8:20am 
Originally posted by Just Jory:
Originally posted by Daynar:
This works nicely. However, I'd highly suggest he use an alarm with room_speed*seconds to ensure it stays up as long as he wants.
Just Jory Sep 8, 2018 @ 8:21am 
Originally posted by Just Jory:
Originally posted by Just Jory:
< >
Showing 1-15 of 16 comments
Per page: 1530 50

Date Posted: Aug 3, 2014 @ 6:38pm
Posts: 16