Page 1 of 1

Please, for the love of God, someone explain to me what /datum/ is

Posted: Fri Apr 19, 2019 9:36 pm
by Timonk
I just look at it as a pile of nonexistent data that still somehow is defined somewhere but I don't know where That should be because I can't find it anywhere ahhhhhhhhh

Re: Please, for the love of God, someone explain to me what /datum/ is

Posted: Fri Apr 19, 2019 10:38 pm
by iamgoofball
Alright, so basically when it comes down to it, a datum is basically just an obj that doesn't have a physical presence, and has incredibly minimal default variables.

For example:

If I want a balloon, I make /obj/balloon.

If I want a record in a database, I make /datum/record.

Basically, if it doesn't need a physical presence and to be something with a sprite on the ground, you use Datum. If not, you use obj/turf/mob/whatever.

There's a lot more detailed shit about it but I'm not the byond expert on the deep level shit. You should stop by #coderbus.

Re: Please, for the love of God, someone explain to me what /datum/ is

Posted: Sat Apr 20, 2019 6:05 am
by Timonk
And if I want to change those values?

Re: Please, for the love of God, someone explain to me what /datum/ is

Posted: Sat Apr 20, 2019 3:19 pm
by iamgoofball
Timonk wrote:And if I want to change those values?
Treat it like any other object or whatever, make a reference to it with a var, tweak the variables on the reference.

Re: Please, for the love of God, someone explain to me what /datum/ is

Posted: Sat Apr 20, 2019 8:07 pm
by bman
what goof said, if it doesnt have a physical presence then you likely want it to be datum, which is just pure code without sprites and shit, but a datum can still be stored inside an object, if for example you wanted a human to make a sound every time he walks, you can create an actual object that makes sound when it moves and then forcibly move inside the human, but that's really unintuitive, it doesnt need a physical presence so creating an object is wasteful, so you create a datum/component that's sent a signal every time the human walks then has the sound play a sound, this is when you use datums.

edit: and there's plenty of other situations and more accurate definitions for this by the way

Re: Please, for the love of God, someone explain to me what /datum/ is

Posted: Sat Apr 20, 2019 9:10 pm
by MrStonedOne
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.

Re: Please, for the love of God, someone explain to me what /datum/ is

Posted: Sat Apr 20, 2019 9:18 pm
by MrStonedOne
Resources:

https://byond.com/docs/ref/ This lists all the default defined types, variables, and procs. A few more that don't show up here can be found by creating a file called "stddef.dm" at the root of any byond project and opening it up.

https://tgstation13.org/wiki/Understanding_SS13_code

https://tgstation13.org/wiki/SS13_for_e ... rogrammers