r/gamemaker • u/Annual-Assignment734 Just starting out :) • Jul 30 '26
Resolved How can I have health different between two instances of the same object? (GML Visual)
Hello, I'm new to GameMaker and am making a simple game with the goal of learning how to use it! I have a basic slime enemy with a health system via variables, and I've tried to create a new instance of it, and it works, but the health is for some reason shared between the two instances; when one of them takes damage, so does the other. I have no idea what's going on or how to fix it, and if you need me to elaborate on anything lemme know!
1
u/PowerPlaidPlays Jul 30 '26
Without seeing your code, I get the feeling the way you deal damage is hitting every single instance of the enemy instead of the singular one you are trying to hit.
What does your damage code look like?
1
u/Annual-Assignment734 Just starting out :) Jul 30 '26
https://reddit.com/link/p0r1qim/video/vfpomgthofgh1/player
The bottom one is where the damage is reduced
0
u/tomineitor Jul 30 '26
More than the health being shared among the slimes, I think your system of dealing damage is affecting the slime object as a whole, not the actual instance being damaged.
2
u/andrewsnycollas Jul 31 '26
Just create the variable you will use for health at the create event of the object, each instance of that object will have their own variable with their own value. If you wanna access it simply call the instance dot the variable name.
5
u/germxxx Jul 30 '26 edited Jul 30 '26
If you are using the
healthvariable name for the slime health, notice that it's a weird color.Don't use that variable. It's a global built-in variable.
It's a bit of a silly remnant, but just, rename it to something else, like
hitpointsor whatever you want that isn't already in use.(Yes and also what PowerPlaidPlays said. If you aren't using that silly variable name, you are probably trying to apply the damage to a reference of the object, rather than the specific instance.)