Sandlight wrote:
I would use "src.health","src.maxHealth", etc. just to remind me of who they belong to. It's not required, but for more complicated, it really helps with the organization and readability.

Not totally relevant to the post, but I tend to avoid arbitrary things in my code. If this was meant to be a beginner tutorial I might take a minute to point it out, but there is no real reason to be clarifying you're accessing src when it's pretty much impossible to think otherwise... like when you define a variable in the local scope with the same name... which is also questionable.
Like I said, it's not required. It's just a personal style of programming of mine.

You do have mob/attacker as one of your parameters. I would assume that it would have the same variables as src. Having src.health and attacker.health can help to distinguish the two healths easier.

And I thought this was a beginner tutorial . =D
Nope. This is about implementation, not syntax.
You'd probably want getHurt() to be this instead:

mob
proc
// take some hurt.
// optional attacker can be provided, for when someone is killing us.
getHurt(damage, mob/attacker)

if(isDead()) return

health -= damage

if(isDead())
die(attacker)


Without that first if statement you can die a second time by getting hit when you're already dead.

Also, I tend to use a boolean variable to determine if the player is dead. Certain actions (ex: movement) aren't allowed while you're dead, but depending on how players respawn they might not become "alive" even though you've restored their "health" var. It's more clear that saying "dead = 0" makes the player alive and able to move, it won't be as clear that "health = maxHealth" would have those side effects.
Forum_account wrote:
Also, I tend to use a boolean variable to determine if the player is dead. Certain actions (ex: movement) aren't allowed while you're dead, but depending on how players respawn they might not become "alive" even though you've restored their "health" var. It's more clear that saying "dead = 0" makes the player alive and able to move, it won't be as clear that "health = maxHealth" would have those side effects.

You make a good point. I considered this myself, after a small discussion with some people. I think it'd be more convenient to have maybe isDying() and isDead(), one for determining if they should die (health < 1, etc...) and one for determining if they have died (dead == TRUE).

That way developers can have the option of having an in-between state. The one I have allows for no in-between, merely death (health < 1, etc...) -> death stuff (announce, give experience) -> respawn (health >= 1).
Page: 1 2