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

How, what and why to code in BYOND.
Post Reply
User avatar
Timonk
Joined: Thu Nov 15, 2018 6:27 pm
Byond Username: Timonk
Location: ur mum

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

Post by Timonk » #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
joooks wrote:
Naloac wrote:
In short, this appeal is denied. Suck my nuts retard.
Quoting a legend, at least im not a faggot lol
See you in 12 months unless you blacklist me for this
Timberpoes wrote: I'm going to admin timonk [...]. Fuck it, he's also now my second host vote if goof rejects.
pikeyeskey13 wrote: ok don't forget to shove it up your ass lmao oops u can delete this one I just wanted to make sure it went through
Agux909 wrote:
Timonk wrote:This is why we make fun of Manuel
Woah bravo there sir, post of the month you saved the thread. I feel overwhelmed by the echo of unlimited wisdom and usefulness sprouting from you post. Every Manuel player now feels embarrased to exist because of your much NEEDED wise words, you sure teached'em all, you genius, IQ lord.


The hut has perished at my hands.
Image




The pink arrow is always right.
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

Post by iamgoofball » #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.
User avatar
Timonk
Joined: Thu Nov 15, 2018 6:27 pm
Byond Username: Timonk
Location: ur mum

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

Post by Timonk » #490190

And if I want to change those values?
joooks wrote:
Naloac wrote:
In short, this appeal is denied. Suck my nuts retard.
Quoting a legend, at least im not a faggot lol
See you in 12 months unless you blacklist me for this
Timberpoes wrote: I'm going to admin timonk [...]. Fuck it, he's also now my second host vote if goof rejects.
pikeyeskey13 wrote: ok don't forget to shove it up your ass lmao oops u can delete this one I just wanted to make sure it went through
Agux909 wrote:
Timonk wrote:This is why we make fun of Manuel
Woah bravo there sir, post of the month you saved the thread. I feel overwhelmed by the echo of unlimited wisdom and usefulness sprouting from you post. Every Manuel player now feels embarrased to exist because of your much NEEDED wise words, you sure teached'em all, you genius, IQ lord.


The hut has perished at my hands.
Image




The pink arrow is always right.
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

Post by iamgoofball » #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.
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

Post by bman » #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
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

Post by MrStonedOne » #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 digg(banned), Steam, IRC, Skype Discord. (!vAKvpFcksg)
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

Post by MrStonedOne » #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 digg(banned), Steam, IRC, Skype Discord. (!vAKvpFcksg)
Image
Post Reply

Who is online

Users browsing this forum: No registered users