ID:1487670
 
(See the best response by Kaiochao.)
Problem description: So I'm trying to use datums more in my projects for more organized code. But I'm struggling with calling procedures under another datum.

Edit: So I found the problem but unsure at to whether this solution would work or not. Since I find a lot of what I've read people usually use, target.DeathCheck(src). Not sure how the target variable will effect it inside the parenthesis.

Code:
mob
var
death/check
proc
Attack(mob/target)
check.DeathCheck(target)

death
proc
DeathCheck(mob/target)



Your datum contains the proc, so you definitely need to be calling it from it. It also doesn't know about any people involved unless you tell it about them, in the arguments or something.

You'll also need to create an instance of the datum before you actually use it. That's just how any object works.

It also doesn't make sense to define the datum as /death/mob. Datums aren't namespaces or interfaces or magical; they're the objects from which atoms inherit. They're the same as atoms, just with less extra built-in stuff.
In response to Kaiochao
Kaiochao wrote:
Your datum contains the proc, so you definitely need to be calling it from it. It also doesn't know about any people involved unless you tell it about them, in the arguments or something.

You'll also need to create an instance of the datum before you actually use it. That's just how any object works.

It also doesn't make sense to define the datum as /death/mob. Datums aren't namespaces; they're the objects from which atoms inherit.

I realised my error once i took a second glance. Didn't mean to put the mob there. I did an edit can you to see if I'm incorrect in the way I'm thinking?
I think that could would look more like this:
mob
proc
Attack(mob/target)
var/death/M = target
M.DeathCheck(src)

death
proc
DeathCheck(mob/killer) //src is now the killed, killer is... The killer..
if(src.hp <= 0)
world << "[killer] has killed [src]."


I've not done much of anything with datums
In response to Rickoshay
That's better, assuming you initialized "check" before its use, and you're okay with not knowing who killed the target.
In response to Howey
This is abusing typecasting and will only result in an error.
In response to Kaiochao
Kaiochao wrote:
That's better, assuming you initialized "check" before its use, and you're okay with not knowing who killed the target.

Could I use check.DeathCheck(target, src)?
Would it be a viable option to add the Attacker to a list? The major problem I can see with this is multiple people being added to the list if there were multiple attacks at once. Not sure how I would go about preventing that either.
In response to Rickoshay
Best response
Yeah, you could tell the proc about both mobs involved.

Regarding the list, I'm not sure why that's even necessary. Arguments only exist within the proc, which is perfectly fine when all you want to do is check if a killer killed someone.

Technically, a "death check" only really needs to know the person being killed in order to answer the question, "is this person dead?" Some other proc could handle what happens between the killer and the target afterwards.

You could also create one death datum in a global variable for all combatants to use, since the datum doesn't currently have anything specific for the object under which it was defined.
Thanks Kaiochao, your help is greatly appreciated.