GML Visual Enemy health Problem

Hello there! Thank you for considering in helping me!

Anyway, before you read, this is a DRAG N' DROP topic as stated above.
You can still suggest me codes, but if you can, explain me in a non-coded way please. :3

Ok there is the problem:

Screenshot (53).png


Screenshot (54).png


I didn't have done anything particular, just dragged and dropped the Test Enemy Health.
 

TheouAegis

Member
Ignore the error message. You have that code somewhere inside an Execute Code block in some object. You probably changed the focus of that code block to Cobby.
 
Ignore the error message. You have that code somewhere inside an Execute Code block in some object. You probably changed the focus of that code block to Cobby.
There is no Execute Code Block in Cobby, but there is one in another Object.
However, that code doesn't use anything related to enemy's health.

Also, it occurs only if Cobby does the action. If I delete it from the room, the problems is solved.
 

TheouAegis

Member
Wait, sorry, not Execute Code. I mean Execute Script. Only scripts take arguments; I was getting ready for bed when I typed that.

Do you have nay scripts in your project that have the variable enemyhealth in them?
 
Wait, sorry, not Execute Code. I mean Execute Script. Only scripts take arguments; I was getting ready for bed when I typed that.

Do you have nay scripts in your project that have the variable enemyhealth in them?
I don't even know how to use them.
So, nope.
Not even one.
 

TheouAegis

Member
Your two conditionals for health have different icons and different variables too. Check your second "health" check as well.
 
I see, you can try changing the lower case to capital and see if the error persists. I'm assuming you downloaded the gmx file from somewhere?
 
Wasn't sure, sorry. If u double click the health check, another window should open. Then from there just change the text for health.
 
Haven't used DniD in awhile. I was thinking of an actual variable check. Forgot that checked the actual health variable. Im sure this goes without asking but just checking. Do you have health set to something in the create event?
 

Yal

šŸ§ *penguin noises*
GMC Elder
*facepalm* how come this topic has gone on for over a dozen posts and nobody has spotted the obvious mistake being made here


health is a global variable shared by all objects. It's meant to be used by the player only. Checking for health's value is checking a completely different variable from enemyhealth. And same thing with Health and health, for that matter.

In the CREATE event of the object, add a code block to set "enemyhealth" to a value. Any value. "unknown variable error" means you're trying to read the value of a variable before it has been given a value. You should get a habit of always setting variables to the desired value in the Create event, then you know they'll have a value in all other events.

Also note that every object instance has their own copy of all variables (unless you explicitly make them global, or use any of the built-in global variables). This also means you will get "unknown variable" errors if you try to check for enemyhealth in an object that isn't the enemy, for instance.
 
I was beginning to realize this. That's why I asked if he did that in my last post. But didn't realize the eneyhealth was different. Never used the built in ones.
 
*facepalm* how come this topic has gone on for over a dozen posts and nobody has spotted the obvious mistake being made here


health is a global variable shared by all objects. It's meant to be used by the player only. Checking for health's value is checking a completely different variable from enemyhealth. And same thing with Health and health, for that matter.

In the CREATE event of the object, add a code block to set "enemyhealth" to a value. Any value. "unknown variable error" means you're trying to read the value of a variable before it has been given a value. You should get a habit of always setting variables to the desired value in the Create event, then you know they'll have a value in all other events.

Also note that every object instance has their own copy of all variables (unless you explicitly make them global, or use any of the built-in global variables). This also means you will get "unknown variable" errors if you try to check for enemyhealth in an object that isn't the enemy, for instance.
*facepalm* ?

Screenshot (56).png
 

TheouAegis

Member
*facepalm* how come this topic has gone on for over a dozen posts and nobody has spotted the obvious mistake being made here


health is a global variable shared by all objects. It's meant to be used by the player only. Checking for health's value is checking a completely different variable from enemyhealth. And same thing with Health and health, for that matter.

In the CREATE event of the object, add a code block to set "enemyhealth" to a value. Any value. "unknown variable error" means you're trying to read the value of a variable before it has been given a value. You should get a habit of always setting variables to the desired value in the Create event, then you know they'll have a value in all other events.

Also note that every object instance has their own copy of all variables (unless you explicitly make them global, or use any of the built-in global variables). This also means you will get "unknown variable" errors if you try to check for enemyhealth in an object that isn't the enemy, for instance.
He didn't check for enemyhealth. He checks for Health and for health. The dozen posts are about finding where the hell he even referenced enemyhealth, because he says it's not in Choppy. And this ain't GMS, so he can't just Ctrl F this stuff.
 
It's as Yal was saying. Health is not a global variable. You are setting everything right. A simple fix, but not a good one, is changing the enemy health check to apply to the enemy object. To do that double click the enemy health test and at the top you will see who the code applies to. Change it to the object.
It's not a good one cause is u have more than one enemy object in a room it won't behave right.
 
Is it showing 1 in the debugger? Or is it dying in one hit? If it's the second we would have to see your collision code. If it's the first do u have another object setting the enemy health?
 
The debugger is alot different than studios been awhile since I used 8's. There should be a red play button next to a green one. The red is to test game with the debugger.
 

TheouAegis

Member
Red "play" arrow.

In the Watchlist, type

instance_position(mouse_x, mouse_y, all)

This will tell you the id of the instance under the mouse at all times. Then look up tgat instancein theInstance Variables list and seewhathealth is set to before the collision.
 
Red "play" arrow.

In the Watchlist, type

instance_position(mouse_x, mouse_y, all)

This will tell you the id of the instance under the mouse at all times. Then look up tgat instancein theInstance Variables list and seewhathealth is set to before the collision.
It just gives me the names of the Instances... :c

Screenshot (59).png
 

TheouAegis

Member
Oh right. Lol i i vent debugged in legacy in a while lol.

Get the id of the instance as above, then put in the watch list

( the_id_you_got ).health

You need the parentheses. Replace the_id_you_got with the number the mouse code showed.

I might have to get on my laptop and look through the debugger again. Lol
 
Oh right. Lol i i vent debugged in legacy in a while lol.

Get the id of the instance as above, then put in the watch list

( the_id_you_got ).health

You need the parentheses. Replace the_id_you_got with the number the mouse code showed.

I might have to get on my laptop and look through the debugger again. Lol
No problem!

By the way, the code was ( the_id_you_got ).enemyhealth not ( the_id_you_got ).health

I checked, and for some reasons, the health starts at 12. ???
And if Cobby gets hit, his health goes to -4 (Normal damage deals 1).
For then get up to 2 thanks to the regenerating health, and then it stops, keeping the health at 2.
 
No problem!

By the way, the code was ( the_id_you_got ).enemyhealth not ( the_id_you_got ).health

I checked, and for some reasons, the health starts at 12. ???
And if Cobby gets hit, his health goes to -4 (Normal damage deals 1).
For then get up to 2 thanks to the regenerating health, and then it stops, keeping the health at 2.
EDIT: Health is 6 if I uncheck Relative. But the other problems occur anyway.
 

TheouAegis

Member
If health is 6 when you uncheck relative, that means you have two instances affecting it.

Click Show Info inside the the object that's manipulating the health. The copy/paste ALL of the info from that window in your next post.
 
Information about object: Fatica_P_C
Sprite: 1p_C
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
for all Cobby: Set Health relative to 6
set Alarm 0 relative to 60
Alarm Event for alarm 0:
for all Cobby: If Health is Smaller Than 6
for all Cobby: Set Health relative to 1
set Alarm 0 relative to 60
Step Event:
for all Cobby: If Health is Equal To 6
set the sprite to 1p_C with subimage 0 and speed 1
for all Cobby: If Health is Smaller Than 6
set the sprite to 2p_C with subimage 0 and speed 1
for all Cobby: If Health is Smaller Than 5
set the sprite to 3p_C with subimage 0 and speed 1
for all Cobby: If Health is Smaller Than 4
set the sprite to 4p_C with subimage 0 and speed 1
for all Cobby: If Health is Smaller Than 3
set the sprite to 5p_C with subimage 0 and speed 1
for all Cobby: If Health is Smaller Than 2
set the sprite to 6p_C with subimage 0 and speed 1
for all Cobby: If Health is Equal To 0
set the sprite to 7p_C with subimage 0 and speed 1
for all Cobby: change the instance into object Nemico, not performing events
Keyboard Event for A-key Key:
if at relative position (0,0) there is object VisualeFollow
jump relative to position (-20,0)
for all roba: jump relative to position (-20,0)
 

TheouAegis

Member
Sorry, Thanksgiving tied me up. Only cameon forquuck glances.

You should be setting alarms to 60, not relative to 60.

That's your code for Fatica_P_C. Now post the info for object Cobby. Let's see if there is a conflict of interests between the two.

In the debugger, watch this:

instance_number(FaticafP_C)

If it is greater than 1, you definitely need to stoo using relative and then find out where the second instance of Fatica is, because you have 2 or more in the room.
 
Information about object: Cobby
Sprite: C_Idle/Mov
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Step Event:
If Sprite Is T-Idle_X
If Health is Smaller Than 2
set the sprite to T-Phew_1_X with subimage 0 and speed 1
If Health is Greater Than 2
If Sprite Is T-Phew_2_X
set the sprite to T-Phew_3_X with subimage 0 and speed 1
if at relative position (30,0) there is object Nemico
for all Fatica_P_T: If Sprite Is <undefined>
execute code:
if(health <= 2 && !instance_exists(Ascia_Pickup))
{
instance_create(x, y, Ascia_Pickup)
}
if relative position (0,1) is collision free for Only solid objects
set the gravity to 2 in direction 270
else
set the gravity to 0 in direction 270
if relative position (-5,0) is collision free for Only solid objects
If Sprite Is C_Dan
jump relative to position (5,0)
if relative position (-5,0) is collision free for Only solid objects
If Sprite Is T-Dan_X
jump relative to position (-5,0)
If Sprite Is C_Idle/Mov
If Health is Smaller Than 2
set the sprite to C_Phew_1 with subimage 0 and speed 1
If Sprite Is C_Phew_2
If Health is Greater Than 2
set the sprite to C_Phew_3 with subimage 0 and speed 1
Collision Event with object Pavimento:
move in direction direction at most 12 till a contact with solid objects
set the vertical speed to 0
Collision Event with object Hit_Box_Pug:
If Sprite Is <undefined>
set the sprite to <undefined> with subimage 0 and speed 1
If Sprite Is C_Idle/Mov
Set Health relative to -2
set the sprite to C_Dan with subimage 0 and speed 1
Keyboard Event for I-key Key:
If Sprite Is C_Idle/Mov
jump relative to position (10,0)
If Sprite Is T-Mov_D
jump relative to position (10,0)
Keyboard Event for M-key Key:
Set Health relative to -1
Keyboard Event for O-key Key:
If Health is Greater Than 1
If Sprite Is C_Idle/Mov
set the sprite to C_Att_1 with subimage 0 and speed 1
If Health is Greater Than 1
If Sprite Is T-Idle_X
set the sprite to T-Att_Asc_1 with subimage 0 and speed 1
Keyboard Event for P-key Key:
if relative position (5,0) is collision free for Only solid objects
If Sprite Is T-Idle_X
set the sprite to Rilascio_1 with subimage 0 and speed 1
for all Fatica_P_T: change the instance into object Fatica_A_T, not performing events
If Sprite Is T-Idle
if at relative position (100,0) there is object Ascia_Pickup
set the sprite to Raccolta_1 with subimage 0 and speed 1
for all Fatica_A_T: change the instance into object Fatica_P_T, not performing events
Keyboard Event for U-key Key:
If Sprite Is C_Idle/Mov
jump relative to position (-10,0)
If Sprite Is T-Mov_S_X
jump relative to position (-10,0)
Other Event: Animation End:
If Sprite Is T-Phew_1_X
set the sprite to T-Phew_2_X with subimage 0 and speed 1
If Sprite Is T-Phew_3_X
set the sprite to T-Idle_X with subimage 0 and speed 1
If Sprite Is C_Phew_1
set the sprite to C_Phew_2 with subimage 0 and speed 1
If Sprite Is C_Phew_3
set the sprite to C_Idle/Mov with subimage 0 and speed 1
If Sprite Is T-Att_Asc_1
set the sprite to T-Att_Asc_2 with subimage 0 and speed 1
Set Health relative to -2
for other object: create instance of object Hit_Box_Asc at relative position (180,70)
else
If Sprite Is T-Att_Asc_2
set the sprite to T-Idle_X with subimage 0 and speed 1
If Sprite Is C_Att_1
Set Health relative to -1
set the sprite to C_Att_2 with subimage 0 and speed 1
for other object: create instance of object Hit_Box_Pug at relative position (-180,70)
else
If Sprite Is C_Att_2
set the sprite to C_Idle/Mov with subimage 0 and speed 1
If Sprite Is Rilascio_1
create instance of object Ascia_Pickup at relative position (50,65)
set the sprite to Rilascio_2 with subimage 0 and speed 1
else
If Sprite Is Rilascio_2
set the sprite to T-Idle with subimage 0 and speed 1
If Sprite Is T-Dan_X
set the sprite to T-Idle_X with subimage 0 and speed 1
If Sprite Is C_Dan
set the sprite to C_Idle/Mov with subimage 0 and speed 1
If Sprite Is Raccolta_1
for all Ascia_Pickup: destroy the instance
set the sprite to Raccolta_2 with subimage 0 and speed 1
else
If Sprite Is Raccolta_2
set the sprite to T-Idle_X with subimage 0 and speed 1
 
If it is greater than 1, you definitely need to stoo using relative and then find out where the second instance of Fatica is, because you have 2 or more in the room.
I don't get why you keep giving me apologies! I should, for all of your time spent! :D
By the way there are no more than one of that instance.
 
Last edited:

TheouAegis

Member
For the issue of Cobby dropping down to -4 HP, do you have an invincibility timer in effect? Typically something like that means the two instances are in contact repeatedly (assuming there is only one Fatica in the room), so it repeatedly reduces Cobby's health. But -4 is an extremely odd amount.

"for other object"
Does that actually work in an Animation End event? In GML, anything "other" related only works in collision events.

You're sure Fatica_A_T and Fatica_P_C aren't in a parent-child relationship? Or have similar code? I see you swap instances between those two objects without performing their events, but if they are already in the room and have similar events, that could cause the compounding issue your code suggests.

T_att and C_att have different amounts of damage they do, it seems. If you were at 1 Health and take 2 damage, that would put you at -1, which means an "if Health equals 0" conditional would never be true. So change that "if Health equals 0" condition to "if Health is smaller than or equal to 0".

The Show Info window doesn't display Start and End blocks. Do you have Start and End blocks properly placed in your code?
 
I've discovered something...

I checked everything you asked me about Cobby, anything about Fatica P_C, and I didn't found ANYTHING wrong in the code.
Cobby is a reversed version of another object (Trax), which has the same identical code except for health, that is enemyhealth instead of health (Trax works completely fine).

There is nothing wrong with it! >:0
Then I tried to open a new GM file, create a random object which only has this:

Information about object: object0
Sprite: sprite0
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
Set Health to 6
Keyboard Event for A-key Key:
Set Health relative to -1


And when I press A, it does the exact same thing as Cobby.
First, goes to 0 enemy health, even if you have 100 enemyhealth, it doesn't care, it will always go to 0, FOR NO REASON.
And then, for no reason as well, doubles the number I used to reduce enemyhealth, from -1 to -2!

???

I'm starting to think that the enemyhealth thing it's broken as hell.
 

Calvert

Member
Create Event:
Set Health to 6
Keyboard Event for A-key Key:
Set Health relative to -1


And when I press A, it does the exact same thing as Cobby.
First, goes to 0 enemy health, even if you have 100 enemyhealth, it doesn't care, it will always go to 0, FOR NO REASON.
Is this a key_pressed event? If not, make it a key_pressed event. Otherwise your health will go down -1 for each frame you have the key held down.

Also, I haven't read most of the posts in this thread so I have no idea if this has already been discussed or not.
 
Is this a key_pressed event? If not, make it a key_pressed event. Otherwise your health will go down -1 for each frame you have the key held down.

Also, I haven't read most of the posts in this thread so I have no idea if this has already been discussed or not.
No, nobody mentioned it, but I'm pretty sure that the key_pressed event isn't that relevant.
 
There's a big difference between the key event and key_pressed event. In the key event, the health is going down by 1 for EVERY STEP the key is pressed down. In the key_pressed event, the health will go down by 1 every time the key is pressed and won't go down again until you release the key and press it again. I don't know if this change will fix your problem, but its definitely the problem in your test object.
 

Calvert

Member
No, nobody mentioned it, but I'm pretty sure that the key_pressed event isn't that relevant.
Great, I'm pretty sure that it's relevant to your new GM file there. If you want your new GM file to work, I recommend setting your key_event to a key_pressed event so your health goes down -1 each time you press the A key. This way your health shouldn't go down to 0 immediately like you mentioned keeps happening.

I think you had a good idea starting a new GM file to re-create your health system. That way you can likely find your problem and fix it in your original GM file.

One step at a time.
 
Last edited:
Great, I'm pretty sure that it's relevant to your new GM file there. If you want your new GM file to work, I recommend setting your key_event to a key_pressed event so your health goes down -1 each time you press the A key. This way your health shouldn't go down to 0 immediately like you mentioned keeps happening.

I think you had a good idea starting a new GM file to re-create your health system. That way you can likely find your problem and fix it in your original GM file.

One step at a time.
Done my tests, and nothing changes.
This occurs even if I don't use a Key bind, but happen even with contact, end animation exc...
 

Calvert

Member
It didn't fix anything.
So you created a new object which only has this:

Code:
Information about object: object0
Sprite: sprite0
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
Set Health to 6
Keyboard Event for A-key Key:
Set Health relative to -1
Except you changed it to be a key_pressed event and not a normal key event. Also, you say that this is all on a new GM file.

How many object0 did you put in the room?
 
Last edited:
So you created a new object which only has this:

Code:
Information about object: object0
Sprite: sprite0
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>
Create Event:
Set Health to 6
Keyboard Event for A-key Key:
Set Health relative to -1
Except you changed it to be a key_pressed event and not a normal key event. Also, you say that this is all on a new GM file.

How many object0 did you put in the room?
1
 
No problem guys! I fixed the problem!
Instead of using the enemyhealth Instance, I used the variabilities one!

And it works perfectly!

Thank you anyway for all of you support! You will not be forgiven! :D
 
Last edited:
Top