ID:1173897
 
(See the best response by Emasym.)
Code:
                if(istype(target,/mob/Player))
var/mob/Player/p = target
p.updateHealth()


Problem description:

No problem as such; it works fine and as intended.

However, it seems a bit clumsy. If target is of type Player, why should I have to create a mob of type Player just to access its procs? I've already 'proved' that target is a player. Is there a better way of doing this or am I just being fussy?
target:updateHealth()


Operator : basically ignores type and hopes there will be proc/verb/var.
<3

Thank you Zaoshi! I've seen you help so many (including myself) around these forums, how is it you don't have a membership yet?
I don't know... I just don't I guess. Not really interested in BYOND, but I used it in the past so I continue lurking around forums.
In response to Zaoshi
Best response
While this definitely works, it is not good practice, and the method in the OP is still preferred.

However, you seem to be forgetting the hierarchical Object-Oriented structure of BYOND. I see you're updating health, so let me just assume it's in some sort of damage-to-target proc.

Right now, in the general /mob proc, you're checking whether the target is a /mob/Player. Allow me to suggest a different way to handle this.

I'll be going by the example that your current proc is one that deals damage

mob
var/hp = 100
proc
damage(mob/target)
target.hp -= 5
target.onHit(src)
onHit(mob/M)
M<<"[name]: Auwch!"

Player
proc
updateHealth()
//update player health

onHit(mob/M)
..() // Outputs the "Auwch!" line
updateHealth()

Monster
onHit(mob/M)
M<<"Prepare to die!"
damage(M)
//Notice how this doesn't call the parent proc
//and as a result will not output "Auwch"


This example is much more flexible thanks to the onHit() proc where everything can be decided when a mob takes damage, and what happens can be adjusted really easily as shown in the example.

However, to stay true to your example, you can define updateHealth on /mob level and only really define it in the on /mob/Player, as so:

mob
proc
updateHealth()

Player
updateHealth()
//update player health


To clarify though, what the OP is doing is called 'type casting' and it's the accepted practice over using the : operator. Using : removes your ability to compile-time check for errors on that specific code.

Type-casting isn't actually creating anything, it's just defining a short-lived variable that won't be taking up any extra memory or resources since it already exists in memory as another variable (target in this case). The only thing you're doing is letting the compiler know what you're doing for error checking and better code readability. By the time the game is fully compiled and running it's all just references to the same point in memory.