ID:161174
 
i dont quite fully understand what the difference between

var/atom/A

and

atom/var/A

is. i know that the first one is just a variable, and the second is a variable that can be set for all atoms right?
atom/var/a <-- The variable 'a' is assigned to /atom with no typecast, it being thought as "/a" (compared to the following)


var/atom/a <-- The variable 'a' is assigned globally assigned (per say) and is thought as "atom/a"


So let's take the following into consideration:
obj/Weapon
var
def = 0
atk = 0
Sword/atk=10
Shield/def=10

mob/var
wep // You'll see why
obj/Weapon/wep2

mob/proc/Attack()
var/mob/M = locate() in get_step(src,src.dir) // locates a /mob one step ahead
if(!M) return // no M, nothing happens
M.TakeHP(str + wep.atk + wep2.atk)


Lets say for the above we created the Sword and equipped it, setting wep and wep2 = the sword object.

In Attack(), wep.atk will give us an error because the variable atk has not been defined globally (remember, wep is defined as var/wep).

wep2.atk works perfectly since wep2 is referring to the path /obj/Weapon, which has the atk variable.
In response to GhostAnime
Put really, really simply.

atom/var/a gives atoms a variable with the name 'a'

var/atom/a gives the var owner a variable which will contain an atom, tada!
Brasuil wrote:
i dont quite fully understand what the difference between

var/atom/A

This declares (creates) a global or local variable (depending on where you put it) named A. It is defined as of the /atom type.

Example:
proc/myproc()
var/atom/A = locate()
//this declares a local variable - it is only available in this proc, and not anywhere else, therefore local to this proc.
if(ismob(A))
var/mob/M = A //this is another local variable - but this is under an indented block, meaning it is local to that block - this variable can only be used inside this if() statement.

var/mob/mymob //variables that are declared on the leftmost level (with no indentation) are global - this variable is accessible from _any_ proc/verb. it's defined as of type /mob


atom/var/A

This declares an object variable (a variable that belongs to an object). The variable is named A and is present on all objects of the /atom type. This variable's type is not defined. Since this syntax seems to confuse you, this is the same as doing:
atom
var/A


The '/' path operator is just a shortcut instead of using another indentation level.
In response to DarkBelthazor
oooh i get it so if you define a var/mob/M, youll get a variable that is a mob, but if you define mob/var/M youll give all mobs a variable...