ID:152551
 
I was wondering if someone could tell me what is a datum, and how to create one. After reading Lummox JR datum tutorial on byondscape, I'm still having a hard time trying to understand the concept...
A datum is just an object like any other. A objects of type /mob, /obj, /turf, /area are all objects, and they are all derives from type /atom. Something derived from /datum is just another kind of object; in fact, /atom derives from /datum.

Here's what the basic, default setup looks like.
datum
atom
area
turf
movable
obj
mob

That is what is already set up for you by default.

Now, since only objects derived from type /atom can be on the map, that means that anything else derived from datum is an object that won't be on the map and therefor won't be seen by players.

Creating your own objects derived from the datum type is just a good way to keep data together, or to give certain kinds of data its own functions. For example...
datum/party
var
list/members[0]
New(list/new_party)
if(new_party) members = new_party
Leave(mob/M)
members.Remove(M)
if(!members.len) del(src)
Split(list/leaving_members)
var/datum/party/new_party = new(leaving_members)
members.Remove(leaving_members)
for(var/mob/M in leaving_members)
M.party = new_party
Experience_Share(amount)
var/n = round(amount / members.len)
for(var/mob/M in members)
M.experience += n

Then if you wanted to make use of that new object...
mob
var
party/party
verb
party_up(mob/M in oview())
if(party)
party.Leave(src)
var/party/new_party
if(M.party)
new_party = M.party
else
new_party = new(list(M))
new_party.members.Add(src)

//The following would be for people who do the follow-the-leader style party and want only the leader to move
client
Move()
if(mob.party && mob.party.members[1]!=mob) return 0
. = ..()

mob
Move()
var/old_loc = loc
. = ..()
if(.)
if(party && party.members.Find(src)!=party.members.len)
var/mob/M = party.members[party.members.Find(src)+1]
M.Move(old_loc, get_dir(M, old_loc))

You can also use this abstract object idea for a lot of other things. My KeyState library uses it to keep track of keyboard information, LummoxJR's SwapMaps library uses it to keep track of map information, Deadron's pathfinding library uses them for path information. They can be used for a wide variety of things to make programming easier.
In response to Loduwijk
I am also gonna use this post for furture references. Thanks for explaining Datums and providing a good example Lummox :D

§atans§pawn
In response to Satans Spawn
Satans Spawn wrote:
Thanks for explaining Datums and providing a good example Lummox :D

You mean Loduwijk?
In response to Loduwijk
Loduwijk wrote:
Satans Spawn wrote:
Thanks for explaining Datums and providing a good example Lummox :D

You mean Loduwijk?

<_<


_>


I have a bad Habit of not looking at who posted what... I think I read something about Lummox before coming here, and saw your name with an L and stopped reading there...

_>

<_<

§atans§pawn
In response to Satans Spawn
Satans Spawn wrote:
I have a bad Habit of not looking at who posted what... I think I read something about Lummox before coming here, and saw your name with an L and stopped reading there...

I mentioned his name in my post, so that is probably what you are talking about.
In response to Loduwijk
Most likely... and Sorry as well... I feel kinda sheepish... Baaaaa

§atans§pawn
In response to Loduwijk
Thanks for explaining...