Object oriented programming basics:
All data has a `type`.
There are simple data types, like number, for numbers, strings, for bits of text, and most languages even have characters, for just 1 character of text (byond does not).
There are also more complex data types, these are really a organized collection of simple data types, as well as attached commands to operate on the data.
The generic term for this is call an "object". (not to be confused with byond objs)
You, as a programmer, define your own objects, making new data types. When doing this, you also choose what object data type to "inherit" from. inheriting from another object data type gives you all of the defined variables (holders for data), and commands (call procs in byond, methods in other languages) of that data type, saving you from having to copy related code.
One common example is a pet datatype, you can make a pet type, giving it a string variable holding its name, a number variable holding its age, and commands on the pet for feeding it or petting it. Then you can make a dog datatype that inherits from pet, so it will already have the name and age variables, and the pet and feed command. You can than make a cat datatype and do the same thing. Doing it this way saves you from having to duplicate code for the commands or the name and age variables.
In byond you can specify the parent type in one of two ways, by including the parent in the type path (/mob/living/carbon/human/dummy). Or by defining the parent_type variable in the code.
Code: Select all
//Make a datatype called "duck" that inherits from /mob
//typepath way
/mob/duck
//parent type way
duck
parent_type = /mob
That's all the it takes to define a new type.
Now, on the bit you care about. What is a /datum
All object oriented languages have a master or root object datatype that object types inherit from if they don't specify a parent type to inherit from. in c# and java, this called "Object". In byond this is called "datum".
da·tum
/ˈdādəm,ˈdadəm/
noun
1. a piece of information.
2.
a fixed starting point of a scale or operation.
Note: Because of the parent_type trick, paths don't always specify their full inheritance. In byond, everything is a datum, but this isn't always specified in the typepath. Some examples.
/atom is really /datum/atom. (atom relates to anything that has a physical presence in the game world.)
/obj is really /datum/atom/movable/obj.
/mob is really /datum/atom/movable/mob.
/turf is really /datum/atom/turf.