GML Visual (SOLVED) Trying to Draw only 3 Units of Health

A

Anti-Icarus

Guest
Following along a few chapters of The Game Maker's Companion, I was able to create a near-perfect Zool game. Given the fact that said book was written with Game Maker 8 aka GM: Legacy in mind, the prescribed methods I used to make it still hold up well in GameMaker: Studio. But by the end of Chapter 6, I encountered one bug that I've been having trouble fixing: getting the game to draw only 3 units of health. Now, the character, Zool, is supposed to have 3 units of health when the game starts. Technically, the game has only one room and the variable health is supposed to be set to 3 at the Room Start event of obj_zool. Whenever Zool gets hit by a hazard or an enemy, he loses 1 unit of health. If all 3 units of health are lost, Zool dies, loses 1 life, and the room resets. Technically speaking, when Zool loses all 3 units of health, the instance of the zool object is replaced by the instance of obj_zool_dead, a child object parented to obj_zool that is set to perform the following actions at the Create event:
obj_zool_dead Create event.png

And the Animation end event:
obj_zool_dead Animation End event.png

Here is how that works in the Zool game made in the original Game Maker software:

View attachment 8398
(Full health)

View attachment 8399
(Low health)

Zool made in GM Legacy, death.png
(Death state)
And here is what has been happening when I attempted to get this to work in GameMaker: Studio:


As this image indicates, the unit's of Zool's health go on forever, meaning that he never never loses health and, therefore, cannot die and lose a life no matter how many times Zool gets hit by hazards. There are 2 possible sources of this problem:
  1. The Room Start event of obj_zool where the variable health is initialized to 3, which is supposed to give Zool only 3 units of health when the room starts.
  2. One of the actions of obj_health in its Step event:
obj_health Create event.png
or its Draw event:
obj_health Draw event.png
Either I overlooked something in Chapter 6 of The Game Maker's Companion or somehow these particular actions just no longer work in GM: Studio as it did in GM: Legacy. What could be preventing Zool from losing no units of heath whatsoever? (By the way, I'm not looking for solutions using GML at the moment. I'm only looking for solutions using only the Drag & Drop method.)
 

Roderick

Member
I don't know D&D very well, but inbetween lines 3 and 4 on that last block, you could set a new variable to min(3, health) and then use that variable instead of health in step 4.
 
A

Anti-Icarus

Guest
I don't know D&D very well, but inbetween lines 3 and 4 on that last block, you could set a new variable to min(3, health) and then use that variable instead of health in step 4.
Well, I tried out that suggestion and it worked! The units are now displaying correctly. When I didn't see the health go down, I altered the health a little bit by replacing the Set Health action that the textbook called for with the Set Variable action that sets the variable health to 3. Using that to tweak the collision events with the hazards and enemies and viola! Zool's health now decreases whenever he gets hit and loses a live when it reaches zero, just like in the original GM Legacy build! I guess a small suggestion can sometimes make a big difference! Thank you!
 
Top