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

How, what and why to code in BYOND.

Moderators: MisterPerson, Code Maintainers

Timonk
 
Joined: Thu Nov 15, 2018 6:27 pm
Byond Username: Timonk

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

Postby Timonk » Fri Apr 19, 2019 9:36 pm #490145

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



User avatar
iamgoofball
Github User
 
Joined: Fri Apr 18, 2014 5:50 pm
Byond Username: Iamgoofball
Github Username: Iamgoofball

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

Postby iamgoofball » Fri Apr 19, 2019 10:38 pm #490150

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.

Timonk
 
Joined: Thu Nov 15, 2018 6:27 pm
Byond Username: Timonk

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

Postby Timonk » Sat Apr 20, 2019 6:05 am #490190

And if I want to change those values?

User avatar
iamgoofball
Github User
 
Joined: Fri Apr 18, 2014 5:50 pm
Byond Username: Iamgoofball
Github Username: Iamgoofball

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

Postby iamgoofball » Sat Apr 20, 2019 3:19 pm #490255

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.

User avatar
bman
Github User
 
Joined: Fri Oct 14, 2016 4:55 pm
Byond Username: Basilman
Github Username: Militaires

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

Postby bman » Sat Apr 20, 2019 8:07 pm #490269

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
pryce bax.
Image
Image

User avatar
MrStonedOne
Host
 
Joined: Mon Apr 14, 2014 10:56 pm
Byond Username: MrStonedOne
Github Username: MrStonedOne

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

Postby MrStonedOne » Sat Apr 20, 2019 9:10 pm #490278

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.
Forum/Wiki Administrator, Server host, Database King, Master Coder


MrStonedOne on Reddit(banned), Steam, IRC, Skype Discord.

[10:55 AM] spookydonut: stonedmc is the work of a criminally insane mad genius

User avatar
MrStonedOne
Host
 
Joined: Mon Apr 14, 2014 10:56 pm
Byond Username: MrStonedOne
Github Username: MrStonedOne

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

Postby MrStonedOne » Sat Apr 20, 2019 9:18 pm #490279

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
Forum/Wiki Administrator, Server host, Database King, Master Coder


MrStonedOne on Reddit(banned), Steam, IRC, Skype Discord.

[10:55 AM] spookydonut: stonedmc is the work of a criminally insane mad genius


Return to Coding

Who is online

Users browsing this forum: zxaber