SMES Manual and SS13 for Experienced Programmers: Difference between pages

From Chompstation Wiki
(Difference between pages)
Jump to navigation Jump to search
imported>Nadyr
(Page restored.)
 
imported>Nadyr
(Page restored.)
 
Line 1: Line 1:
[[File:SMES.png][[File:terminal.png]]
{{BayPage}}
Superconducting Magnetic Energy Storage (often shortened to SMES) is a device used to store electrical power. While SMES units are very effective, they are also expensive, requiring high end circuit board and expensive parts. If you need to quickly replace the SMES you may try using cheaper but less powerful Cell Rack PSU instead. SMES units may be upgraded to increase their capacity and/or maximal input/output levels.
{{hatnote|This article was gratefully copied from the corresponding page on the [http://tgstation13.org/wiki/SS13_for_experienced_programmers /tg/station13 wiki].}}
Other related guides: [[Basics of Coding in BYOND]] and the [[Guide to Mapping]]


== Configuration ==
So you know how to write programs in other languages and would like a quick guide on how to understand and code for SS13? Good, this is the guide for you. It likely doesn't contain everything that you need to know but it's a start.
SMES units may be configured via interface which is opened by left-clicking with empty hand on the SMES. Alternatively you may use the RCON console to operate most SMESs on station. The interface looks like this: <br>
[[File:SMES_GUI.png]]


=== Input ===
== Syntax ==
Each SMES needs terminal to operate properly. This terminal allows you to charge the SMES from one power network, and output into another one. By using apropriate controls in the GUI you may set any input value up to certain cap. This cap can be increased by upgrading the SMES unit, as described further in this guide. Also, please note that setting larger input than available will cause the SMES to enter "Partially Charging" state. This means the SMES is still charging, but not at set input rate. You may choose from two input options - OFF and AUTO.
=== Output ===
The SMES outputs power into wire placed directly under it. Usually, you want to keep output lower than input, however sometimes you may have to increase output to compensate for larger demand. This is common with main [[Guide to Power#Engines|Engine]] SMES when setting up [[Guide to Power#SMES_Settings|Substations]]. The output rate is also capped and also upgradeable. You may choose from two output options which are self explanatory - ONLINE and OFFLINE.


=== Values ===
*Semicolons at the end are not mandatory,
<small><i>See also: [[Guide to Power#SMES_Settings|Guide to Power]]</i></small>
*Loop, proc, object, variable etc. spans are determined by indentations (similar to Python, see examples below)
  /obj
    var
      i1
      i2
      i3
is the same as (Strongly recommended you use this layout to make searching for variable and proc definitions easier.)
  /obj
    var/i1
    var/i2
    var/i3
which is inturn the same as
  /obj/var/i1
  /obj/var/i2
  /obj/var/i3
*This guide uses the word 'object' for any defined type (see [[#Variable types|Variable types]]) and the word 'obj' for derivatives of atom/obj, which are all objects which can be placed on the map.
*This guide uses the word 'AI controlled' for behavior to do with an [[AI]] player controlling an item. The term 'Game controlled' is used when refering to behavior which the script itself determins (Usually called AI controlled creatures or NPCs)
*All things are inherited from parent objects. If a variable is defined in /obj/item, it doesn't need to be (actually can't be) redefined in /obj/item/weapon.


These are example settings for few SMESs around the station. You may choose different settings, depending on available power and other factors. Try to consult the [[Chief Engineer]] when unsure.
=== [http://www.byond.com/members/?command=reference&path=var Variables] ===
Variables are very general, Byond makes no difference in the declaration of strings, integers, etc. (Similar to PHP)


{| class="wikitable"
==== [http://www.byond.com/members/?command=reference&path=var Predefined variables] ====
There is a lot of predefined variables for objects in BYOND, but the most important are:
*'''[http://www.byond.com/members/?command=reference&path=proc%2Fvar%2Fsrc src]''' - a variable equal to the object containing the proc or verb. It is defined to have the same type as that object. (Similar to "this" in Java or C++)
*'''[http://www.byond.com/members/?command=reference&path=proc%2Fvar%2Fusr usr]''' - a mob variable (var/mob/usr) containing the mob of the player who executed the current verb, or whose action ultimately called the current proc. '''A good rule of thumb is to never put usr in a proc.''' If src would not be the correct choice, it is better to send another argument to your proc with the information it needs.
*'''[http://www.byond.com/members/?command=reference&path=proc%2Fvar%2Fargs args]''' - a list of the arguments passed to the proc or verb.
*'''[http://www.byond.com/members/?command=reference&path=datum%2Fvar%2Fvars vars]''' - a list of object variables. If the variable name is used as an index into the list, the value of that variable is accessed.
 
For more SS13 specific variables see [[#SS13 common variable meanings|SS13 common variable meanings]]
 
==== Variable definition ====
 
=====Basic definitions=====
  var/j
  var/i = 4
  var/a, b, c
 
=====Complex definitions=====
The general syntax is [http://www.byond.com/members/?command=reference&path=var var/type/variable_name = value]
 
Examples:
  var/obj/item/I = new/obj/item
  [http://www.byond.com/members/?command=reference&path=operator%2F%40dt%3B I.name] = "Some item"
 
Datum definition and declaration of a variable of that datum type:
  datum/test_datum
    var/test_variable = 0 //declaration of the test_variable var
   
    proc/set_as(var/i) //proc definition within the test_datum datum
      test_variable = i //set the test_variable var to the value in the argument
 
  var/datum/test_datum/TD = new/datum/test_datum //TD will now be a reference to a datum of type test_datum
  TD.test_variable = 4  //Byond doesn't know of private variables, so you can set any variables like this
  [http://www.byond.com/members/?command=reference&path=world world] [http://www.byond.com/members/?command=reference&path=operator%2F%26lt%3B%26lt%3B <<] TD.test_variable //will output 4 to all connected users
  TD.set_as(10) //Will call the set_as proc in the datum with the argument 10
  TD.test_variable //will output 10 to all connected users
 
==== Bitflags ====
Bitflags are variables which use bits instead of numbers to determine conditions. The bit operators are [http://www.byond.com/members/?command=reference&path=operator%2F%26 &] and [http://www.byond.com/members/?command=reference&path=operator%2F%7C |]. For now, you should know that bitflag operators use the binary value of numbers to determine the result. So [http://www.byond.com/members/?command=reference&path=operator%2F%26 13 & 3] will result in 1. ([http://www.byond.com/members/?command=reference&path=operator%2F%26 1101 & 0011 = 0001]) and [http://www.byond.com/members/?command=reference&path=operator%2F%7C 13 | 3 = 15] ([http://www.byond.com/members/?command=reference&path=operator%2F%7C 1101 | 0011 = 1111]) see [[#If|if]] for uses
 
==== Variable types ====
[http://www.byond.com/members/?command=reference&path=var reference]
 
*[http://www.byond.com/members/?command=reference&path=datum datum] - ordinary object type (class in java)
*[http://www.byond.com/members/?command=reference&path=atom atom] - atom derives into obj, turf, mob and area
*[http://www.byond.com/members/?command=reference&path=turf turf] - tiles which make up the floors, walls and space on SS13
*[http://www.byond.com/members/?command=reference&path=area area] - areas are grouped locations. They combine many turfs and it gives some common properties. Power, atmosphere, etc. are determined by areas
*[http://www.byond.com/members/?command=reference&path=mob mob] - an object with life, be it game controlled or player controlled.
*[http://www.byond.com/members/?command=reference&path=obj obj] - objects which can be placed on the map
*[http://www.byond.com/members/?command=reference&path=client client] - a new client object is created for each connected player
*[http://www.byond.com/members/?command=reference&path=list list] - a list of elements. The first element in a list called L is L[1]
*[http://www.byond.com/members/?command=reference&path=world world] - this is a variable where some global variables for the entire world can be set. World's contents var contains all atoms currently in the game world.
 
==== [http://www.byond.com/members/?command=reference&path=operator%2F%26lt%3B%26lt%3B%2Foutput Outputting messages] ====
The most basic way of outputting messages is with the [http://www.byond.com/members/?command=reference&path=operator%2F%26lt%3B%26lt%3B%2Foutput '<<' output operator].
 
  [http://www.byond.com/members/?command=reference&path=world world] [http://www.byond.com/members/?command=reference&path=operator%2F%26lt%3B%26lt%3B <<] "Hello World!" //Outputs a message to all clients in the world
  [http://www.byond.com/members/?command=reference&path=proc%2Fvar%2Fusr usr] [http://www.byond.com/members/?command=reference&path=operator%2F%26lt%3B%26lt%3B <<] "Hello usr" //Outputs a message to only the user who is tied to the calling of the proc which contains this.
 
===== Output with variables =====
  var/s1 = "Hello"
  var/s2 = "World"
  var/i = 2011
  [http://www.byond.com/members/?command=reference&path=world world] [http://www.byond.com/members/?command=reference&path=operator%2F%26lt%3B%26lt%3B <<] "[s1] [s2], this guide was written in [i]" //Returns "Hello World, this guide was written in 2011"
 
==== Determining variable types in code ====
The [http://www.byond.com/members/?command=reference&path=proc%2Fistype istype()] proc will come in handy
 
Example
  var/obj/item/weapon/W = new/obj/item/weapon/baton
  if([http://www.byond.com/members/?command=reference&path=proc%2Fistype istype](W,/obj/item/weapon/baton))
    [http://www.byond.com/members/?command=reference&path=world world] << "It's a baton!"
 
The second argument is optional, if it's omitted, the variable will be checked against its declared type, like
  var/obj/item/weapon/W = new/obj/item/weapon/baton
  if([http://www.byond.com/members/?command=reference&path=proc%2Fistype istype](W))
    [http://www.byond.com/members/?command=reference&path=world world] << "It's a weapon!"
 
Standard code for getting specific arguments from variables which have a type that is a subclass of the type the current proc treats them with (see any attackby() proc for examples). Note that the example below is of a proc which is globaly defined, not tied to the object. It doesn't make much sense to do it like this but it works for the purposes of the example. /obj objects don't have the 'amount' variable, it's defined in /obj/item/stack (as ilustrated by the oversimplified definition of classes below. Also note where var/ is used and where it isn't).
  /obj
    var/name = "Object"
 
  /obj/item
    name = "Item"
 
  /obj/item/stack
    name = "Stack"
    var/amount = 50
 
  proc/get_amount(var/obj/O)
    if([http://www.byond.com/members/?command=reference&path=proc%2Fistype istype](O,/obj/item/stack))
      var/obj/item/stack/S = O
      return [http://www.byond.com/members/?command=reference&path=operator%2F%40dt%3B S.amount]
 
There is another way of doing this. I'll show you that it exists but it is NOT TO BE USED.
  proc/get_aount(var/obj/S)
    if([http://www.byond.com/members/?command=reference&path=proc%2Fistype istype](O,/obj/item/stack))
      return [http://www.byond.com/members/?command=reference&path=operator%2F%3A O:amount]
The [http://www.byond.com/members/?command=reference&path=operator%2F%3A colon operator] (:) in the example above tells the byond compiler: "I know what I'm doing, so ignore the fact the object doesn't have this variable, I'll make sure it works myself." The problem is that people will revise your code and use it in ways you never planed for. This means something might eventually make the O:amount throw exceptions in the form of runtime errors. Some variables might eventually need to be removed or replaced and this is impossible when they are used with object:variable as the compiler will not throw an error when the variable is removed. The error will only become apparent after the game is ran on the live server which might cause it to crash. So just don't use this method, ever.
 
There are some shortcuts to [http://www.byond.com/members/?command=reference&path=proc%2Fistype istype()] proc:<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fisarea isarea(variable)] = istype(variable, /area)<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fisicon isicon(variable)] = istype(variable, /icon)<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fismob ismob(variable)]  = istype(variable, /mob)<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fisobj isobj(variable)]  = istype(variable, /obj)<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fisturf isturf(variable)] = istype(variable, /turf)<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fisloc isloc(variable)]  = ismob(variable) || isobj(variable) || isturf(variable) || isarea(variable)
 
==== Switching between variable types in code ====
 
Byond defined:<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fascii2text ascii2text]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Ffile2text file2text]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Flist2params list2params]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fnum2text num2text]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Fparams2list params2list]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Ftext2ascii text2ascii]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Ftext2file text2file]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Ftext2num text2num]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Ftext2path text2path]<br>
[http://www.byond.com/members/?command=reference&path=proc%2Ftime2text time2text]<br>
 
SS13 Defined:<br>
text2dir(direction)<br>
dir2text(direction)<br>
dd_file2list(file_path, separator)<br>
dd_text2list(text, separator, var/list/withinList)<br>
dd_text2List(text, separator, var/list/withinList)<br>
dd_list2text(var/list/the_list, separator)<br>
angle2dir(var/degree)<br>
angle2text(var/degree)<br>
 
For more useful procs see<br>
[http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/procs/helpers.dm code/defines/procs/helpers.dm]<br>
[http://code.google.com/p/tgstation13/source/browse/trunk/code/game/objects/items/helper_procs.dm code/game/objects/items/helper_procs.dm]
 
=== [http://www.byond.com/members/?command=reference&path=proc%2Fif If] ===
 
Ifs default to checking for true if not otherwise stated. True is defined for all variable types as empty, 0 or non-existant (null).
  if(condition)
    action_true()
  else
    action_false()
 
==== Common variable behavior in if statements: ====
{|
!Variable type
!False when
!True when
|-
|-
! Location !! Input !! Output !! Other notes
!String (text / ascii)
|"" or null
|Anything else
|-
|-
| Engine Room SMES || 250kW, Auto || 250kW, Online || Generally, you want the Engine SMES to be charged to ensure cooling will remain operational.
!Int / Real
|0 or null
|Anything else
|-
|-
| Main SMES || 1000kW, Auto || 950kW, Online || You may have to lower the input if engine is producing less than 750kW. On the other hand, if it's producing more increase input.
!datum, atom
|-
|null
| Atmospherics SMES || 250kW, Auto || 250kW, Online || Some things, especially pumps, use large amounts of power. This means atmospherics needs a lot of power.
|Anything else
|-
| Substation SMESs || Variable || Variable || Refer to page [[Guide to Power#SMES_Settings|Substations]] for more information.
|}
|}


==== [http://www.byond.com/members/?command=reference&path=operator Logical operators] ====
Pretty standard:
  [http://www.byond.com/members/?command=reference&path=operator%2F%21 !statement1] //NOT statement1
  [http://www.byond.com/members/?command=reference&path=operator%2F%26%26 (statement1) && (statement2)] //statement1 AND statement2
  [http://www.byond.com/members/?command=reference&path=operator%2F%7C%7C (statement1) || (statement2)] //statement1 OR statement2
  [http://www.byond.com/members/?command=reference&path=operator%2F%3D%3D ==] //equals
  [http://www.byond.com/members/?command=reference&path=operator%2F%21%3D !=] //not equal
  [http://www.byond.com/members/?command=reference&path=operator%2F%26lt%3B <] ([http://www.byond.com/members/?command=reference&path=operator%2F%26lt%3B%3D <=]) //less (or equal)
  [http://www.byond.com/members/?command=reference&path=operator%2F%26gt%3B >] ([http://www.byond.com/members/?command=reference&path=operator%2F%26gt%3B%3D >=]) //more (or equal)
  [http://www.byond.com/members/?command=reference&path=operator%2F%26 &] //bitflag AND operator. 13 & 3 = 1 (1101 & 0011 = 0001)
  [http://www.byond.com/members/?command=reference&path=operator%2F%7C |] //bitflag OR operator. 13 | 3 = 15 (1101 | 0011 = 1111)
Byond does not recognize the === (identical) operator. More operators can be found in the left menu on the [http://www.byond.com/members/?command=reference&path=operator reference page]
=== [http://www.byond.com/members/?command=reference&path=proc%2Fwhile While] ===
Byond will cancel a loop if it reaches a certain number of iteration and give a runtime error out of fear of infinite loops. Same applies for recursions.
Same as anywhere else
  while(condition)
    action1()
All loops understand the [http://www.byond.com/members/?command=reference&path=proc%2Fcontinue continue] and [http://www.byond.com/members/?command=reference&path=proc%2Fbreak break] commands
=== For ===
All loops understand the [http://www.byond.com/members/?command=reference&path=proc%2Fcontinue continue] and [http://www.byond.com/members/?command=reference&path=proc%2Fbreak break] commands
For combines the for loop and foreach loop:
====  [http://www.byond.com/members/?command=reference&path=proc%2Ffor%2Floop For loop] ====
  for(var/i = 1; i <= 10; i++)
    [http://www.byond.com/members/?command=reference&path=world world] << i //Will write (each in a new line) 1 2 3 4 5 6 7 8 9 10
==== [http://www.byond.com/members/?command=reference&path=proc%2Ffor%2Flist For each] ====
  for(var/obj/item/weapon/baton/B [http://www.byond.com/members/?command=reference&path=operator%2Fin in] world)  //will iterate through world.contents (which contains all atoms in the world) and only pick those which are of the given type (/obj/item/weapon/baton)
    B.name = "Smelly baton" //Will apply the new name to the baton in the current iteration loop
=== [http://www.byond.com/members/?command=reference&path=proc%2Fdo Do - While] ===
The Do while operator is not commonly used in SS13 code, Byond does support it tho.
  var/i = 3
  do
    world << i--
  while(i)
All loops understand the [http://www.byond.com/members/?command=reference&path=proc%2Fcontinue continue] and [http://www.byond.com/members/?command=reference&path=proc%2Fbreak break] commands
=== [http://www.byond.com/members/?command=reference&path=datum Defining objects] ===
Doesn't matter if you want a [http://www.byond.com/members/?command=reference&path=datum datum] or [http://www.byond.com/members/?command=reference&path=atom atom], the definition of objects is the same and simple:
  /obj/item/weapon/item1 //will nmake a new object of type obj.
    var/item_property = 5 //Will define a new variable type for all item1 objs
    name = "Testing Item" //The name var is already defined in parent objects so it is not defined here, but only assigned a new valie.
 
  /obj/item/weapon/item1/[http://www.byond.com/members/?command=reference&path=datum%2Fproc%2FNew New()] //Constructor proc
    [[#..()|..()]] //should always be present in New() procs, see [[#..()|..()]] for more information
    item_property = 3 //An action that is performed in the object constructor.
=== [http://www.byond.com/members/?command=reference&path=proc Procs] (Methods, functions, procedures) ===
You're used to the standards of methods, functions and procedures, right? Well procs ignore some aspects of these. They can best be compared to Java methods, as they're tied to specific objects. They cannot be defined as static, private, public, etc. tho. You can write static methods, however the compiler will not restrict you from calling them in a non-static way or environment. Same applies for non-static methods.
  proc/proc_name(var/argument1, var/argument2)
    [http://www.byond.com/members/?command=reference&path=world world] << "[argument1] [argument2]"
The above would declare a global proc. If you wish to tie it to a certain level
==== ..() ====
This is the same as super() in Java. It calls the parent object type's proc with the same name and same arguments.
Example:
  /obj/item
    name = "Item"
 
  /obj/item/New() //New() is the proc that gets called whenever a new object of this type is created. A constructor if you will.
    src.name = "It's an item!"
 
  /obj/item/stack
    name = "Stack"
 
  /obj/item/stack/New()
    src.name = "It's a stack!"
    ..()
If you have the code from the example above and create a new object of type /obj/item/stack, it will first make the item in the game world with the name "Stack", because it's defined to be that by default. Then the New() proc will be called immedietally after. This will change the name to "It's a Stack!" but the call of the parent type's New() proc with the ..() command will then set it to "It's an item!". So in the end, the new object will be called "It's an item!". The ..() command is however very important in many cases as some things are defined only in the common parent's New() procs. In Del(), the proc which gets called prior to an object's deletion, it requires the code to get to the root Del() proc to even delete it. See examples of Del() in the code.
== Important procs ==
=== [http://www.byond.com/members/?command=reference&path=atom%2Fproc%2FNew New()] ===
This proc is called whenever a new instance of the object is created. It can have arguments if needed. It should call ..() where applicable so that parent constructors can be applied.
If you wish to create a New() proc for [[#Variable types|atoms]] with custom arguments, ensure the first argument is for the object's location. Example:
  obj/item/weapon/my_item/New(var/location, var/i)
    ..()
    //Whatever else you need to do
To make a general object use
  [http://www.byond.com/members/?command=reference&path=proc%2Fnew new] /datum/test_datum
To make an atom (which usually has a locaiton)
  [http://www.byond.com/members/?command=reference&path=proc%2Fnew new] /obj/item/weapon(src.loc)
For the custom example above, the code to create a new such object would be: The 5 is just an example of a value which could be assigned to the var/i in the constructor.
  [http://www.byond.com/members/?command=reference&path=proc%2Fnew new] /obj/item/weapon/my_item(src.loc, 5)
Where src is the proc owner, which contains the line above. src.loc is the locaiton of the src object.
=== [http://www.byond.com/members/?command=reference&path=datum%2Fproc%2FDel Del()] ===
This proc gets called before an object's delection. It MUST call ..() at the end as the actual deletion is done in the root Del() proc.
An object is deleted by using the del(O) proc with O being the object to be deleted.
=== attack_hand(mob/M as mob) ===
Whenever a user (M) clicks on the object with an empty active hand
=== attack_paw(mob/M as mob) ===
Whenever a monkey (M) clicks the object with an empty active hand
If a custom attack_paw(mob/user) proc is not written for an atom, it defaults to calling attack_hand(user)
=== attack_ai(mob/user) ===
Whenever an AI or cyborg clicks the object with an empty active hand
If a custom attack_ai(mob/user) proc is not written for an atom, it defaults to calling attack_hand(user)
=== attack(mob/M as mob, mob/user as mob) ===
When the object is used to attack mob M by mob user
=== attackby(obj/item/W, mob/user) ===
When the object is being attacked by user with W (Example: If you click on wires with wirecutters)
=== ex_act(severity) ===
How the item reacts to explosions. Severity can either be 1, 2 or 3 with 1 being the most destructive.
=== blob_act() ===
How the item reacts to a blob (magma) attack
=== emp_act(severity) ===
How the item reacts to an EMP. Severity can either be 1 or 2 with 1 being the more powerful EMP surge.
=== [http://www.byond.com/members/?command=reference&path=datum%2Fproc%2FTopic Topic(href, href_list)] ===
This one's called when you click a link in a pop-up window. Like when you increase the output of [[SMES cells]]. The href_list variable is the important one as it's a parsed version of the arguments you add into a link. To make a link in the pop-up window, add the following line to the text you display (dat in the example):
  <nowiki>dat += </nowiki>[http://www.byond.com/members/?command=reference&path=proc%2Ftext text](<nowiki>"<A href='?src=\ref[src];select=[i]'>[src.name]</a><br>")</nowiki>
Check the code for more examples of this.
=== process() ===
This gets called for all objects on every tick. If possible, avoid it as it's processor heavy, but for some things it just can't be avoided.
== SS13 common variable meanings ==
=== Datum ===
Datums have the smallest number of pre-defined variables. These are present in all objects in the game:
  type //The type of an object. If your object is of type /obj/item/weapon/shovel writing the following: new src.type(src.loc) will make another shovel in the same tile.
  parent_type //Parent type of /obj/item/weapon/shovel is /obj/item/weapon... seems streight-foward enough.
  tag //The tag is used to help you identify things when using several instances. It has to be set manually for each instance tho. Lazy coders and mappers resulted in not many tags being used. Instances in the map editor are sorted by tag.
  vars //List of object vars the datum has defined
=== Atom ===
These variables are shared by all areas, mobs, objs and turfs.
  contents //List of contents. Closets store their contents in this var as do all storage items. All the items on a turf are in the turf's contents var.
  density //If density is at 0, you can walk over the object, if it's set to 1, you can't.
  desc //Description. When you right-click and examine an object, this will show under the name.
  dir //Object direction. Sprites have a direction variable which can have 8 'legal' states. [[Understanding SS13 code#Direction (dir) var|More info]]
  gender //not used
  icon //The dmi file where the sprite is saved. Must be written in single quotations (Example: 'items.dmi')
  icon_state //The name of the sprite in the dmi file. If it's not a valid name or is left blank, the sprite without a name in the dmi file will be used. If such a sprite doesn't exist it will default to being blank.
  invisibility //Invisibility is used to determine what you can and what you can't see. Check the code or wait for someone who knows how exactly this works to write it here.
  infra_luminosity //Only mecha use this
  underlays //List of images (see image() proc) which are underlayed under the current sprite
  overlays //List of images (see image() proc) which are overlayed over the current sprite
  loc //Contains a reference to the turf file where the object currently is.
  layer //A numerical variable which determins how objects are layered. Tables with a layer of 2.8 are always under most items which have a layer of 3.0. Layers go up to 20, which is reserved for HUD items.
  luminosity //How much the item will glow. Note that the picking up and dropping of luminous items needs to be specially handled. See flashlight code for an example.
  mouse_over_pointer //not used
  mouse_drag_pointer //(almost) not used
  mouse_drop_pointer //not used
  mouse_drop_zone //not used
  mouse_opacity //Used in a few places. Check the description in the reference page
  name //The name of the object which is displayed when you right click the object and in the bottom left of the screen when you hover your mouse over it.
  opacity //Whether you can see through/past it (glass, floor) when set to 0 or whether you can't (walls, mecha) when set to 1.
  pixel_x //How many pixels in the x direction should the sprite be offset from the starting set. See the APC's New() proc for an example and how fire alarms are defined on the map. pixel_x = -5 will move it 5 pixels to the left and pixel_x = 5 will move it 5 pixels to the right
  pixel_y //Same as pixel_y but in the y direction. Positive values move it to the north, negative to the south.
  pixel_z //Used in isometric maps, so it's not used in SS13
  suffix //Rarely used. See the reference page for more information
  text //How to represent the object on text clients. Not used.
  type //The type of the object
  vars //See [[#Datum|Datum]] above
  verbs //The verbs you can use with the item. Verbs are the options in the right click menu.
  x //X position, read only. Set the loc variable to move it or use the inbulit functions.
  y //Y position, read only.
  z //Z position (Which z-level it's on), read only.
=== Area ===
  var/requires_power = 1 //Areas which are to work without an APC (Such as centcom areas) should have this at 0. All other areas should have it at 1.
  var/music = null //Music to be played when you enter the area.
  [http://www.byond.com/members/?command=reference&path=atom%2Fvar%2Fluminosity luminosity] = 0 //Areas which should be lit at all times (such as space and centcom) should have this at 1 as well as the sd_lighting var at 0
  var/sd_lighting = 0 //This var determines whether dynamic lighting is to be calculated for the area's tiles. Turn this to off only for areas which have the luminosity var set to 1
Most other variables exist only for technical reasons and should not be messed with unless done through existing procs, they are defined in:
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/area/Space%20Station%2013%20areas.dm code/defines/area/Space Station 13 areas.dm]
=== Mob ===
There is a huge amount of variables for mobs. Take a look at the following files:
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/mob.dm code/defines/mob/mob.dm]
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/dead/observer.dm code/defines/mob/dead/observer.dm]
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/living/living.dm code/defines/mob/living/living.dm]
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/living/carbon/carbon.dm code/defines/mob/living/carbon/carbon.dm]
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/living/carbon/human.dm code/defines/mob/living/carbon/human.dm]
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/living/carbon/monkey.dm code/defines/mob/living/carbon/monkey.dm]
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/living/silicon/silicon.dm code/defines/mob/living/silicon/silicon.dm]
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/living/silicon/ai.dm code/defines/mob/living/silicon/ai.dm]
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/mob/living/silicon/robot.dm code/defines/mob/living/silicon/robot.dm]
There are also additional files for aliens, larva, facehuggers and more there, but the files above will have most of the variables you might need.
=== Obj ===
  var/m_amt = 0 // How much metal the item has. Used to determine how much metal you get when feeding it into an autolathe and how much it costs to produce it at the lathe
  var/g_amt = 0 // How much glass the item has. Used to determine how much glass you get when feeding it into an autolathe and how much it costs to produce it at the lathe
  var/w_amt = 0 // waster amounts. Not used
  var/origin_tech = null //Used by R&D to determine what research bonuses it grants. See examples in item definitions in code.
  var/reliability = 100 //Used by SOME devices to determine how reliable they are. The number represents the percentual chance for them to work properly.
  var/unacidable = 0 //universal "unacidabliness" var, objects with this set to 1 cannot be destroyed by acids.
  var/throwforce = 0 //The amount of damage applies to a target when they're hit by the item.
More variables are defined in:
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/obj.dm code/defines/obj.dm]
==== Item ====
Items are objs which can be picked up. They're divided into several categories according to their function.
/obj/item is defined in the following file:
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/obj.dm code/defines/obj.dm]
It adds the following variables (Look at the file for more, but these are the more important ones):
  var/force = null //This determins how much damage the target takes when they're attacked by the item in hand. Small items usually have it at 0, medium ones between 5 and 10, rare and powerful items around 10-15 and two-handed items at 15 and more. Syndicate items have it even higher at 40 and more.
  var/item_state = null //This it the var that determines which sprite will be used for the item from icons/mob/items_lefthand.dmi and items_righthand.dmi.
  var/damtype = "brute" //Determines what damage type the item produces.
  var/health = null //Some items use this to determine when they'll break from use or damage. Not common tho.
  var/hitsound = null //Sound that's played when you hit something with the item. Not commonly used.
  var/w_class = 3.0 //Weight class.
    // w_class = 1 means it's an item that can fit in a pocket (diskette, pen, cigarette packet)
    // w_class = 2 means the item can't fit in pockets but can fit in a box (clipboard, analyzer, cleaner)
    // w_class = 3 means the item can't fit in a box but can fit in backpacks (box, rods, metal)
    // w_class = 4 means the item can't even fit in a backpack (packpack, pickaxe, fireaxe)
    // w_class = 5 is used but not for weight classes.
  var/wielded = 0 //Used for double-handed items which can be carried in one hand but needs to be wielded by two hands before they can be used. This is determined by code when wielding and unwielding. All items should start with this at 0.
  var/twohanded = 0 ///Set this to 1 if your item is two-handed.
  flags = FPRINT | TABLEPASS //Flags
==== Machinery ====
Defined in:
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/obj/machinery.dm code/defines/obj/machinery.dm]
Machinery are objs which cannot be picked up and generally require power to operate. They have the following vars defined for all of them:
  var/use_power = 0 //Determines if and how much power the machine will use each tick.
    //use_power = 0 - no power is used
    //use_power = 1 - idle power is used
    //use_power = 2 - active power is used
  var/idle_power_usage = 0 //How many watts of power the machine will use each tick when use_power is set to 1
  var/active_power_usage = 0 //How many watts of power the machine will use each tick when use_power is set to 2
  var/power_channel = EQUIP //Determines which APC power category the device falls under. EQUIP, ENVIRON or LIGHT
  var/list/component_parts = null //A list of parts needed to construct the machine from a machine frame.
=== Turf ===


== Deconstruction ==
  var/intact = 1 //This determines if the turf will hide pipes, cable and such. Set to 1 to hide and to 0 to not hide them. Only pipes and wire with level set to 1 will be hidden. Set their level var to 2 to keep them from being hidden.
=== Required tools ===
  var/blocks_air = 0 //Determines if the turf prevents air from passing (walls) if set to 1.
*[[File:Screwdriver_tool.png]] Screwdriver
Other variables exist but they're tied to atmospherics code which is not to be touched as whenever anything is changed in it it results in a million things breaking.
*[[File:Crowbar.png]] Crowbar
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/turf.dm code/defines/turf.dm]
*[[File:Wirecutters.png]] Wirecutters
*[[File:Welderon.gif]] Welding Tool
*[[File:Wrench.png]] Wrench
*[[File:Yellowgloves.png]] Insultated Gloves (optional, but reccomended)
*[[File:Multitool.png]] Multitool (optional, only if you decide to disable failsafes)


=== Preparations ===
==== Simulated ====
# First of all you should ensure the SMES is discharged. While there is a workaround, it may (read: will) cause an injury and/or damage.
# Open the SMES's interface by left clicking it. Ensure both Input and Output are turned Off.
# Use screwdriver on the SMES to open the access panel.
# Use wirecutters on the SMES to cut the terminal. If the terminal is missing (or destroyed) simply skip this step.


=== Deconstruction Steps ===
Simulated floors are tiles which simulate air movement and temperature. The station is made entirely from these while centcom is made from unsimulated floors to prevent massive and unneeded lag.
# Complete everything in Preparations
# (OPTIONAL) Use multitool on the SMES to disconnect safety circuit. This step may be skipped if you completely discharged the SMES. '''DO NOT PROCEED IF SMES IS CHARGED ABOVE 50%''', usually, anything below 15% is safe(with gloves). Anything above 50% is likely to kill you.
# Use crowbar on the SMES to begin removing the components. This may take up to 60 seconds, depending on amount of coils in the SMES. Basic SMESs should take approximately 10 seconds. SMES will turn into machine frame and few components. You may use these components for research or for repairs/upgrades.
# Use wirecutters to remove cables from the machine frame
# Use wrench to dismantle the machine frame


== SMES Failure ==
  var/wet = 0 //If this it a positive number, it is wet and you'll slip on it if you run.
Disabling failsafes, as outlined in Hacking section of this page may cause SMES Failure when removing the components (crowbar step), or adding new components (inserting new coils). Chance of "something bad" happening is directly proportional to SMES charge percentage. SMES charged to 75% has 75% probability of failing, etc. If this failure happens, effects are once again related to charge percentage.
  var/thermite = 0 //Will be set to 1 when thermite is poured on it.
*'''Discharge''' - (Always) The SMES will lose ALL it's remaining charge.
*'''Sparks''' - (Always) Mostly harmless, some sparks will fly from the SMES, potentionally igniting fire if flammable material is nearby.
*'''Electrocution''' - (Always) Shocks the user. Please note that while insultated gloves mitigate the effect, they aren't guaranteed to 100% protect you. Damage scales with charge percentage. Anything above 60% charge is instant-kill even with gloves.
*'''EM Pulse''' - (above 15% charge) Causes electromagnetic pulse which breaks nearby electronics. This usually trips fire alarms, breaks consoles, and may even kill/injure the AI/cyborgs/people with prosthetics depending on situation. Size of EM Pulse is proportional to amount of stored power.
*'''APC Overload''' - (above 35% charge) Overloads lighting circuits of few APCs connected to the SMES's output. Please note that having something between the SMES and APC (such as, another SMES) will prevent the damage. Chance is proportional to amount of stored power.
*'''APC Failure''' - (above 35% charge) Completely breaks few APCs in SMES's output. Same rule as above applies.
*'''Magnetic Containment Failure''' - (above 60% charge) The worst thing that can happen. If SMES's magnetic containment fails remaining charge is released in form of violent explosion. The SMES is completely destroyed, as well as few nearby tiles. This almost always causes hull breach, and the explosion may gib you. After this failure is triggered you have 30-60 seconds before the SMES blows up.


== Hacking ==
===== Simulated floors =====
SMES units may be hacked to enable or disable various features. Remember to wear your [[File:Yellowgloves.png]] protective equipment or risk injury. To access the wiring open front panel with screwdriver. Then click the SMES with empty hand to open up wiring window. There are five wires, which have randomized colours every round.
* Input - Cutting this will cause the SMES to stop inputting. Pulsing will temporarily disable input.
* Output - Cutting this will cause the SMES to stop outputting. Pulsing will temporarily disable output.
* RCON - Cutting this will disable RCON (Remote CONtrol), hiding the SMES from control consoles. It also disables AI control. Pulsing does nothing.
* Failsafes - Cutting will allow you to modify the SMES even if it is charged. Please note that this may result in catastrophic overload if charge is large enough. Pulsing does nothing.
* Grounding - Cutting or pulsing this wire will overload the SMES, causing quick dissipation of stored energy. This energy may however damage or destroy APCs in output power network, so it is advised to either disconnect the SMES, or at least use [[Guide to Power#SMES_SettingsSubstations]] to prevent damage to many APCs. Mending will restore grounding and stop the overload. This is highly similar failure of charged SMES, but with less risks involved for the user. Remember that doing this as non-antagonist is not a good idea.


== Construction ==
  var/icon_regular_floor = "floor" //Determines what icon the steel version of the floor should have. Determined at floor creation (New() proc). If the icon_state of the floor at that point is one from the global icons_to_ignore_at_floor_init var, then this variable is assigned the value "floor". The icons_to_ignore_at_floor_init list contains broken, plating, burnt and non-steel icon_states from icons/turf/floors.dmi
=== Required Tools ===
  heat_capacity = 10000 //When a fire (hotspot) on the tile exceeds this number, the floor has a chance of melting. The more the number is exceeded, the higher the chance of melting.
*[[File:CableCoils.png]] Cable Coil, 2x (two full coils)
  var/broken = 0 //This mostly only determins if you'll get the tile back when you use the crowbar
*[[File:Metal.png]] Metal Sheets, 5x
  var/burnt = 0 //This mostly only determins if you'll get the tile back when you use the crowbar
*[[File:Circuitboard.png]] SMES Circuit Board - May be obtained from Research, or salvaged from existing SMESs
  var/obj/item/stack/tile/floor_tile = new/obj/item/stack/tile/steel //What floor tile is on the tile
*[[File:SMESCoil.png]] Superconducting Magnetic Coil - May be obtained from Cargo or salvaged from existing SMES. You need at least one coil, but adding more coils increases capacity and input/output cap of the SMES. You may add up to six coils into single SMES.
*[[File:Yellowgloves.png]] Insultated Gloves - Optional, but reccomended (espicially if you are going to manipulate wiring)


=== Construction Steps ===
Simulated floors are defined in:
# Use your metal sheets to build machine frame.
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/game/turf.dm code/game/turf.dm]
# Use your cable coil on machine frame to add wires.
# (OPTIONAL) place wire under the machine frame. The SMES will output into this wire.
# Use your SMES Circuit Board on wired machine frame.
# Add 30 pieces of cable (one full length cable coil).
# Add one superconducting magnetic coil.
# Finalise the SMES with screwdriver.


=== Terminal ===
===== Simulated walls =====
New SMES starts without terminal. Furthermore, terminals may be damaged by explosions or similar effects. Fortunately, installing new terminal is easy.
# Open interface of your SMES and turn it's input and output OFF.
# Use screwdriver on the SMES to open the cover.
# Use cable coil on the SMES to add new terminal. You need 10 pieces of cable for this. If you make a mistake use wirecutters to remove the terminal and repeat this step.
# Use screwdriver on the SMES to close the cover.


=== RCON Settings ===
Doesn't really contain any special new variables.
RCON, or Remote CONtrol, allows remote operation of SMESs from RCON console. To allow usage of RCON you have to set RCON tag. This tag has to be unique (ie. do not use tag already used by another SMES). To set new tag click the SMES with multitool. If you wish to disable RCON you may either cut apropriate wire (see Hacking section), or use tag "NO_TAG".


== Upgrading ==
Defined in:
There are three types of coils in existence:<br>
  [http://code.google.com/p/tgstation13/source/browse/trunk/code/defines/turf.dm code/defines/turf.dm]
'''Superconductive Capacitance Coils''' highly increase the amount of energy the SMES can store.<br>
'''Superconductive Transference Coils''' highly increase the maximum input and output rate.<br>
'''Superconductive Magnetic Coils''' increase both storage and transfer rate, but at a lesser extent.<br>
There are two of each type of coils in the Engineering Hard Storage, in one of the crates.<br>


When building an SMES you may add only a single Magnetic Coil into it. However, you may add up to five more coils later. This process is slightly more complex than terminal replacement.
[[Category:Guides]] [[Category:Game Resources]]
# Ensure the SMES is discharged. Alternatively, you may disable the failsafes (see point 4.). Please read the "SMES Failure" section of this guide before proceeding.
{{Contribution guides}}
# Open interface of your SMES and turn it's input and output OFF.
# Use screwdriver on the SMES to open the cover.
# (OPTIONAL) Disable failsafes by cutting the correct wire (see Hacking section).
# Use your superconducting magnetic coil(s) on the SMES to install them.
# (OPTIONAL) Re-enable failsafes if you disabled them.
# Use screwdriver on the SMES to close the cover.

Latest revision as of 02:34, 11 November 2019

This article or section is from the Baystation 12 wiki.

This article or section is directly taken from the Baystation 12 wiki, and should not be fully relied on for CHOMPstation. You can help by updating it.

Other related guides: Basics of Coding in BYOND and the Guide to Mapping

So you know how to write programs in other languages and would like a quick guide on how to understand and code for SS13? Good, this is the guide for you. It likely doesn't contain everything that you need to know but it's a start.

Syntax

  • Semicolons at the end are not mandatory,
  • Loop, proc, object, variable etc. spans are determined by indentations (similar to Python, see examples below)
 /obj
   var
     i1
     i2
     i3

is the same as (Strongly recommended you use this layout to make searching for variable and proc definitions easier.)

 /obj
   var/i1
   var/i2
   var/i3

which is inturn the same as

 /obj/var/i1
 /obj/var/i2
 /obj/var/i3
  • This guide uses the word 'object' for any defined type (see Variable types) and the word 'obj' for derivatives of atom/obj, which are all objects which can be placed on the map.
  • This guide uses the word 'AI controlled' for behavior to do with an AI player controlling an item. The term 'Game controlled' is used when refering to behavior which the script itself determins (Usually called AI controlled creatures or NPCs)
  • All things are inherited from parent objects. If a variable is defined in /obj/item, it doesn't need to be (actually can't be) redefined in /obj/item/weapon.

Variables

Variables are very general, Byond makes no difference in the declaration of strings, integers, etc. (Similar to PHP)

Predefined variables

There is a lot of predefined variables for objects in BYOND, but the most important are:

  • src - a variable equal to the object containing the proc or verb. It is defined to have the same type as that object. (Similar to "this" in Java or C++)
  • usr - a mob variable (var/mob/usr) containing the mob of the player who executed the current verb, or whose action ultimately called the current proc. A good rule of thumb is to never put usr in a proc. If src would not be the correct choice, it is better to send another argument to your proc with the information it needs.
  • args - a list of the arguments passed to the proc or verb.
  • vars - a list of object variables. If the variable name is used as an index into the list, the value of that variable is accessed.

For more SS13 specific variables see SS13 common variable meanings

Variable definition

Basic definitions
 var/j
 var/i = 4
 var/a, b, c
Complex definitions

The general syntax is var/type/variable_name = value

Examples:

 var/obj/item/I = new/obj/item
 I.name = "Some item"

Datum definition and declaration of a variable of that datum type:

 datum/test_datum
   var/test_variable = 0 //declaration of the test_variable var
   
   proc/set_as(var/i) //proc definition within the test_datum datum
     test_variable = i //set the test_variable var to the value in the argument
 
 var/datum/test_datum/TD = new/datum/test_datum //TD will now be a reference to a datum of type test_datum
 TD.test_variable = 4  //Byond doesn't know of private variables, so you can set any variables like this
 world << TD.test_variable //will output 4 to all connected users
 TD.set_as(10) //Will call the set_as proc in the datum with the argument 10
 TD.test_variable //will output 10 to all connected users

Bitflags

Bitflags are variables which use bits instead of numbers to determine conditions. The bit operators are & and |. For now, you should know that bitflag operators use the binary value of numbers to determine the result. So 13 & 3 will result in 1. (1101 & 0011 = 0001) and 13 | 3 = 15 (1101 | 0011 = 1111) see if for uses

Variable types

reference

  • datum - ordinary object type (class in java)
  • atom - atom derives into obj, turf, mob and area
  • turf - tiles which make up the floors, walls and space on SS13
  • area - areas are grouped locations. They combine many turfs and it gives some common properties. Power, atmosphere, etc. are determined by areas
  • mob - an object with life, be it game controlled or player controlled.
  • obj - objects which can be placed on the map
  • client - a new client object is created for each connected player
  • list - a list of elements. The first element in a list called L is L[1]
  • world - this is a variable where some global variables for the entire world can be set. World's contents var contains all atoms currently in the game world.

Outputting messages

The most basic way of outputting messages is with the '<<' output operator.

 world << "Hello World!" //Outputs a message to all clients in the world
 usr << "Hello usr" //Outputs a message to only the user who is tied to the calling of the proc which contains this.
Output with variables
 var/s1 = "Hello"
 var/s2 = "World"
 var/i = 2011
 world << "[s1] [s2], this guide was written in [i]" //Returns "Hello World, this guide was written in 2011"

Determining variable types in code

The istype() proc will come in handy

Example

 var/obj/item/weapon/W = new/obj/item/weapon/baton
 if(istype(W,/obj/item/weapon/baton))
   world << "It's a baton!"

The second argument is optional, if it's omitted, the variable will be checked against its declared type, like

 var/obj/item/weapon/W = new/obj/item/weapon/baton
 if(istype(W))
   world << "It's a weapon!"

Standard code for getting specific arguments from variables which have a type that is a subclass of the type the current proc treats them with (see any attackby() proc for examples). Note that the example below is of a proc which is globaly defined, not tied to the object. It doesn't make much sense to do it like this but it works for the purposes of the example. /obj objects don't have the 'amount' variable, it's defined in /obj/item/stack (as ilustrated by the oversimplified definition of classes below. Also note where var/ is used and where it isn't).

 /obj
   var/name = "Object"
 
 /obj/item
   name = "Item"
 
 /obj/item/stack
   name = "Stack"
   var/amount = 50
 
 proc/get_amount(var/obj/O)
   if(istype(O,/obj/item/stack))
     var/obj/item/stack/S = O
     return S.amount

There is another way of doing this. I'll show you that it exists but it is NOT TO BE USED.

 proc/get_aount(var/obj/S)
   if(istype(O,/obj/item/stack))
     return O:amount

The colon operator (:) in the example above tells the byond compiler: "I know what I'm doing, so ignore the fact the object doesn't have this variable, I'll make sure it works myself." The problem is that people will revise your code and use it in ways you never planed for. This means something might eventually make the O:amount throw exceptions in the form of runtime errors. Some variables might eventually need to be removed or replaced and this is impossible when they are used with object:variable as the compiler will not throw an error when the variable is removed. The error will only become apparent after the game is ran on the live server which might cause it to crash. So just don't use this method, ever.

There are some shortcuts to istype() proc:
isarea(variable) = istype(variable, /area)
isicon(variable) = istype(variable, /icon)
ismob(variable) = istype(variable, /mob)
isobj(variable) = istype(variable, /obj)
isturf(variable) = istype(variable, /turf)
isloc(variable) = ismob(variable) || isobj(variable) || isturf(variable) || isarea(variable)

Switching between variable types in code

Byond defined:
ascii2text
file2text
list2params
num2text
params2list
text2ascii
text2file
text2num
text2path
time2text

SS13 Defined:
text2dir(direction)
dir2text(direction)
dd_file2list(file_path, separator)
dd_text2list(text, separator, var/list/withinList)
dd_text2List(text, separator, var/list/withinList)
dd_list2text(var/list/the_list, separator)
angle2dir(var/degree)
angle2text(var/degree)

For more useful procs see
code/defines/procs/helpers.dm
code/game/objects/items/helper_procs.dm

If

Ifs default to checking for true if not otherwise stated. True is defined for all variable types as empty, 0 or non-existant (null).

 if(condition)
   action_true()
 else
   action_false()

Common variable behavior in if statements:

Variable type False when True when
String (text / ascii) "" or null Anything else
Int / Real 0 or null Anything else
datum, atom null Anything else

Logical operators

Pretty standard:

 !statement1 //NOT statement1
 (statement1) && (statement2) //statement1 AND statement2
 (statement1) || (statement2) //statement1 OR statement2
 == //equals
 != //not equal
 < (<=) //less (or equal)
 > (>=) //more (or equal)
 & //bitflag AND operator. 13 & 3 = 1 (1101 & 0011 = 0001)
 | //bitflag OR operator. 13 | 3 = 15 (1101 | 0011 = 1111)

Byond does not recognize the === (identical) operator. More operators can be found in the left menu on the reference page

While

Byond will cancel a loop if it reaches a certain number of iteration and give a runtime error out of fear of infinite loops. Same applies for recursions. Same as anywhere else

 while(condition)
   action1()

All loops understand the continue and break commands

For

All loops understand the continue and break commands

For combines the for loop and foreach loop:

For loop

 for(var/i = 1; i <= 10; i++)
   world << i //Will write (each in a new line) 1 2 3 4 5 6 7 8 9 10

For each

 for(var/obj/item/weapon/baton/B in world)  //will iterate through world.contents (which contains all atoms in the world) and only pick those which are of the given type (/obj/item/weapon/baton)
   B.name = "Smelly baton" //Will apply the new name to the baton in the current iteration loop

Do - While

The Do while operator is not commonly used in SS13 code, Byond does support it tho.

 var/i = 3
 do
   world << i--
 while(i)

All loops understand the continue and break commands

Defining objects

Doesn't matter if you want a datum or atom, the definition of objects is the same and simple:

 /obj/item/weapon/item1 //will nmake a new object of type obj.
   var/item_property = 5 //Will define a new variable type for all item1 objs
   name = "Testing Item" //The name var is already defined in parent objects so it is not defined here, but only assigned a new valie.
 
 /obj/item/weapon/item1/New() //Constructor proc
   ..() //should always be present in New() procs, see ..() for more information
   item_property = 3 //An action that is performed in the object constructor.

Procs (Methods, functions, procedures)

You're used to the standards of methods, functions and procedures, right? Well procs ignore some aspects of these. They can best be compared to Java methods, as they're tied to specific objects. They cannot be defined as static, private, public, etc. tho. You can write static methods, however the compiler will not restrict you from calling them in a non-static way or environment. Same applies for non-static methods.

 proc/proc_name(var/argument1, var/argument2)
   world << "[argument1] [argument2]"

The above would declare a global proc. If you wish to tie it to a certain level

..()

This is the same as super() in Java. It calls the parent object type's proc with the same name and same arguments.

Example:

 /obj/item
   name = "Item"
 
 /obj/item/New() //New() is the proc that gets called whenever a new object of this type is created. A constructor if you will.
   src.name = "It's an item!"
 
 /obj/item/stack
   name = "Stack"
 
 /obj/item/stack/New() 
   src.name = "It's a stack!"
   ..()

If you have the code from the example above and create a new object of type /obj/item/stack, it will first make the item in the game world with the name "Stack", because it's defined to be that by default. Then the New() proc will be called immedietally after. This will change the name to "It's a Stack!" but the call of the parent type's New() proc with the ..() command will then set it to "It's an item!". So in the end, the new object will be called "It's an item!". The ..() command is however very important in many cases as some things are defined only in the common parent's New() procs. In Del(), the proc which gets called prior to an object's deletion, it requires the code to get to the root Del() proc to even delete it. See examples of Del() in the code.

Important procs

New()

This proc is called whenever a new instance of the object is created. It can have arguments if needed. It should call ..() where applicable so that parent constructors can be applied.

If you wish to create a New() proc for atoms with custom arguments, ensure the first argument is for the object's location. Example:

 obj/item/weapon/my_item/New(var/location, var/i)
   ..()
   //Whatever else you need to do

To make a general object use

 new /datum/test_datum

To make an atom (which usually has a locaiton)

 new /obj/item/weapon(src.loc)

For the custom example above, the code to create a new such object would be: The 5 is just an example of a value which could be assigned to the var/i in the constructor.

 new /obj/item/weapon/my_item(src.loc, 5)

Where src is the proc owner, which contains the line above. src.loc is the locaiton of the src object.

Del()

This proc gets called before an object's delection. It MUST call ..() at the end as the actual deletion is done in the root Del() proc.

An object is deleted by using the del(O) proc with O being the object to be deleted.

attack_hand(mob/M as mob)

Whenever a user (M) clicks on the object with an empty active hand

attack_paw(mob/M as mob)

Whenever a monkey (M) clicks the object with an empty active hand

If a custom attack_paw(mob/user) proc is not written for an atom, it defaults to calling attack_hand(user)

attack_ai(mob/user)

Whenever an AI or cyborg clicks the object with an empty active hand

If a custom attack_ai(mob/user) proc is not written for an atom, it defaults to calling attack_hand(user)

attack(mob/M as mob, mob/user as mob)

When the object is used to attack mob M by mob user

attackby(obj/item/W, mob/user)

When the object is being attacked by user with W (Example: If you click on wires with wirecutters)

ex_act(severity)

How the item reacts to explosions. Severity can either be 1, 2 or 3 with 1 being the most destructive.

blob_act()

How the item reacts to a blob (magma) attack

emp_act(severity)

How the item reacts to an EMP. Severity can either be 1 or 2 with 1 being the more powerful EMP surge.

Topic(href, href_list)

This one's called when you click a link in a pop-up window. Like when you increase the output of SMES cells. The href_list variable is the important one as it's a parsed version of the arguments you add into a link. To make a link in the pop-up window, add the following line to the text you display (dat in the example):

 dat += text("<A href='?src=\ref[src];select=[i]'>[src.name]</a><br>")

Check the code for more examples of this.

process()

This gets called for all objects on every tick. If possible, avoid it as it's processor heavy, but for some things it just can't be avoided.

SS13 common variable meanings

Datum

Datums have the smallest number of pre-defined variables. These are present in all objects in the game:

 type //The type of an object. If your object is of type /obj/item/weapon/shovel writing the following: new src.type(src.loc) will make another shovel in the same tile.
 parent_type //Parent type of /obj/item/weapon/shovel is /obj/item/weapon... seems streight-foward enough.
 tag //The tag is used to help you identify things when using several instances. It has to be set manually for each instance tho. Lazy coders and mappers resulted in not many tags being used. Instances in the map editor are sorted by tag.
 vars //List of object vars the datum has defined

Atom

These variables are shared by all areas, mobs, objs and turfs.

 contents //List of contents. Closets store their contents in this var as do all storage items. All the items on a turf are in the turf's contents var.
 density //If density is at 0, you can walk over the object, if it's set to 1, you can't.
 desc //Description. When you right-click and examine an object, this will show under the name.
 dir //Object direction. Sprites have a direction variable which can have 8 'legal' states. More info
 gender //not used
 icon //The dmi file where the sprite is saved. Must be written in single quotations (Example: 'items.dmi')
 icon_state //The name of the sprite in the dmi file. If it's not a valid name or is left blank, the sprite without a name in the dmi file will be used. If such a sprite doesn't exist it will default to being blank.
 invisibility //Invisibility is used to determine what you can and what you can't see. Check the code or wait for someone who knows how exactly this works to write it here.
 infra_luminosity //Only mecha use this
 underlays //List of images (see image() proc) which are underlayed under the current sprite
 overlays //List of images (see image() proc) which are overlayed over the current sprite
 loc //Contains a reference to the turf file where the object currently is.
 layer //A numerical variable which determins how objects are layered. Tables with a layer of 2.8 are always under most items which have a layer of 3.0. Layers go up to 20, which is reserved for HUD items.
 luminosity //How much the item will glow. Note that the picking up and dropping of luminous items needs to be specially handled. See flashlight code for an example.
 mouse_over_pointer //not used
 mouse_drag_pointer //(almost) not used
 mouse_drop_pointer //not used
 mouse_drop_zone //not used
 mouse_opacity //Used in a few places. Check the description in the reference page
 name //The name of the object which is displayed when you right click the object and in the bottom left of the screen when you hover your mouse over it.
 opacity //Whether you can see through/past it (glass, floor) when set to 0 or whether you can't (walls, mecha) when set to 1.
 pixel_x //How many pixels in the x direction should the sprite be offset from the starting set. See the APC's New() proc for an example and how fire alarms are defined on the map. pixel_x = -5 will move it 5 pixels to the left and pixel_x = 5 will move it 5 pixels to the right
 pixel_y //Same as pixel_y but in the y direction. Positive values move it to the north, negative to the south.
 pixel_z //Used in isometric maps, so it's not used in SS13
 suffix //Rarely used. See the reference page for more information
 text //How to represent the object on text clients. Not used.
 type //The type of the object
 vars //See Datum above
 verbs //The verbs you can use with the item. Verbs are the options in the right click menu.
 x //X position, read only. Set the loc variable to move it or use the inbulit functions.
 y //Y position, read only. 
 z //Z position (Which z-level it's on), read only.

Area

 var/requires_power = 1 //Areas which are to work without an APC (Such as centcom areas) should have this at 0. All other areas should have it at 1.
 var/music = null //Music to be played when you enter the area.
 luminosity = 0 //Areas which should be lit at all times (such as space and centcom) should have this at 1 as well as the sd_lighting var at 0
 var/sd_lighting = 0 //This var determines whether dynamic lighting is to be calculated for the area's tiles. Turn this to off only for areas which have the luminosity var set to 1

Most other variables exist only for technical reasons and should not be messed with unless done through existing procs, they are defined in:

 code/defines/area/Space Station 13 areas.dm

Mob

There is a huge amount of variables for mobs. Take a look at the following files:

 code/defines/mob/mob.dm
 code/defines/mob/dead/observer.dm
 code/defines/mob/living/living.dm
 code/defines/mob/living/carbon/carbon.dm
 code/defines/mob/living/carbon/human.dm
 code/defines/mob/living/carbon/monkey.dm
 code/defines/mob/living/silicon/silicon.dm
 code/defines/mob/living/silicon/ai.dm
 code/defines/mob/living/silicon/robot.dm

There are also additional files for aliens, larva, facehuggers and more there, but the files above will have most of the variables you might need.

Obj

 var/m_amt = 0	// How much metal the item has. Used to determine how much metal you get when feeding it into an autolathe and how much it costs to produce it at the lathe
 var/g_amt = 0	// How much glass the item has. Used to determine how much glass you get when feeding it into an autolathe and how much it costs to produce it at the lathe
 var/w_amt = 0	// waster amounts. Not used
 var/origin_tech = null //Used by R&D to determine what research bonuses it grants. See examples in item definitions in code.
 var/reliability = 100	//Used by SOME devices to determine how reliable they are. The number represents the percentual chance for them to work properly.
 var/unacidable = 0 //universal "unacidabliness" var, objects with this set to 1 cannot be destroyed by acids.
 var/throwforce = 0 //The amount of damage applies to a target when they're hit by the item.

More variables are defined in:

 code/defines/obj.dm

Item

Items are objs which can be picked up. They're divided into several categories according to their function.

/obj/item is defined in the following file:

 code/defines/obj.dm

It adds the following variables (Look at the file for more, but these are the more important ones):

 var/force = null //This determins how much damage the target takes when they're attacked by the item in hand. Small items usually have it at 0, medium ones between 5 and 10, rare and powerful items around 10-15 and two-handed items at 15 and more. Syndicate items have it even higher at 40 and more.
 var/item_state = null //This it the var that determines which sprite will be used for the item from icons/mob/items_lefthand.dmi and items_righthand.dmi.
 var/damtype = "brute" //Determines what damage type the item produces.
 var/health = null //Some items use this to determine when they'll break from use or damage. Not common tho.
 var/hitsound = null //Sound that's played when you hit something with the item. Not commonly used.
 var/w_class = 3.0 //Weight class.
   // w_class = 1 means it's an item that can fit in a pocket (diskette, pen, cigarette packet)
   // w_class = 2 means the item can't fit in pockets but can fit in a box (clipboard, analyzer, cleaner)
   // w_class = 3 means the item can't fit in a box but can fit in backpacks (box, rods, metal)
   // w_class = 4 means the item can't even fit in a backpack (packpack, pickaxe, fireaxe)
   // w_class = 5 is used but not for weight classes.
 var/wielded = 0 //Used for double-handed items which can be carried in one hand but needs to be wielded by two hands before they can be used. This is determined by code when wielding and unwielding. All items should start with this at 0.
 var/twohanded = 0 ///Set this to 1 if your item is two-handed.
 flags = FPRINT | TABLEPASS //Flags

Machinery

Defined in:

 code/defines/obj/machinery.dm

Machinery are objs which cannot be picked up and generally require power to operate. They have the following vars defined for all of them:

 var/use_power = 0 //Determines if and how much power the machine will use each tick.
   //use_power = 0 - no power is used
   //use_power = 1 - idle power is used
   //use_power = 2 - active power is used
 var/idle_power_usage = 0 //How many watts of power the machine will use each tick when use_power is set to 1
 var/active_power_usage = 0 //How many watts of power the machine will use each tick when use_power is set to 2
 var/power_channel = EQUIP //Determines which APC power category the device falls under. EQUIP, ENVIRON or LIGHT
 var/list/component_parts = null //A list of parts needed to construct the machine from a machine frame.

Turf

 var/intact = 1 //This determines if the turf will hide pipes, cable and such. Set to 1 to hide and to 0 to not hide them. Only pipes and wire with level set to 1 will be hidden. Set their level var to 2 to keep them from being hidden.
 var/blocks_air = 0 //Determines if the turf prevents air from passing (walls) if set to 1.

Other variables exist but they're tied to atmospherics code which is not to be touched as whenever anything is changed in it it results in a million things breaking.

 code/defines/turf.dm

Simulated

Simulated floors are tiles which simulate air movement and temperature. The station is made entirely from these while centcom is made from unsimulated floors to prevent massive and unneeded lag.

 var/wet = 0 //If this it a positive number, it is wet and you'll slip on it if you run.
 var/thermite = 0 //Will be set to 1 when thermite is poured on it.
Simulated floors
 var/icon_regular_floor = "floor" //Determines what icon the steel version of the floor should have. Determined at floor creation (New() proc). If the icon_state of the floor at that point is one from the global icons_to_ignore_at_floor_init var, then this variable is assigned the value "floor". The icons_to_ignore_at_floor_init list contains broken, plating, burnt and non-steel icon_states from icons/turf/floors.dmi
 heat_capacity = 10000 //When a fire (hotspot) on the tile exceeds this number, the floor has a chance of melting. The more the number is exceeded, the higher the chance of melting.
 var/broken = 0 //This mostly only determins if you'll get the tile back when you use the crowbar
 var/burnt = 0 //This mostly only determins if you'll get the tile back when you use the crowbar
 var/obj/item/stack/tile/floor_tile = new/obj/item/stack/tile/steel //What floor tile is on the tile

Simulated floors are defined in:

 code/game/turf.dm
Simulated walls

Doesn't really contain any special new variables.

Defined in:

 code/defines/turf.dm
Contribution Guides & Game Resources
General Guide to Setting Up a Server, Downloading the Source Code, Guide to Contributing to the Game, Game Resources category
Coding Basics of Coding in BYOND, SS13 for Experienced Programmers, [NanoUI]
Mapping Guide to Mapping
Spriting Guide to Spriting
Wiki Guide to Contributing to the Wiki, Style Guide