HealthManagement

Hi ! I’ve recently switched from Unity to Defold and am a bit confused about how I would go about running a health management rule set, so how to
-take damage from an enemy which would then update the current health of the player

  • collide with a healing object which would heal the player by a certain amount so say a small healer would heal 1 point and a big healer would heal 5 points
    -also have this health updated live on screen?
  • but if the maximum health has been achieved, then to take no action and the healer object is ignored
    but also make sure the code doesn’t break…in unity it would be something like "if health >= max health then health = max health "
1 Like

Hi and welcome!

What have you tried so far and what about it is confusing for you? Both of your points are made quite the same way in Defold as in Unity where the only difference is one is in Lua and the other in C#. Make sure you read up a bit on Defold by following some tutorials I would recommend colorslide and warbattle. I would also strongly recommend you to read about lua too.

3 Likes

hey ! thanks! i’ll give lua a try and I’ve just seen that warbattle example game, the main thing that is confusing me is how to set a rule so that the health can’t go above a certain level, and also where to call the current health from unless that is just labelled as self.health ?

You would probably do a player_manager.lua (read up a bit about lua modules). That module would be required in your player.script and game.gui_script. Your player.script would listen for messages that tells him “someone hit you” or “I picked up a health glob”. When reciving the message the player.script would update the player_manager and tell the game.gui_script that it need to update the .gui that’s displaying the players health.

In short, use a lua module to hold the player values. Send messages to update the player when being interacted with.

4 Likes

thanks i’ll dive into it and give it a try!