Applies to:DM Reference
Status: Open

Issue hasn't been assigned a status value.
(I filed this under dream maker because it refers more to the documentation)


A 'global' variable normally refers to a variable with no scope, accessible globally.


thing = 1
if (thing)
thing = 0

Byond has a var keyword, called global. This var keyword is for vars inside of types. IE:

thing = 1

It means that that var will only exist once for all instances of its type, in this case that var will only exist once for all mobs, ie its shared across everything in it's type. (ie: static in other languages like php/c++/c#/java)

It DOES NOT mean that you can access it everywhere like a global var (from above)

Isn't that confusing? It is to me, and most of the programmers at /tg/station13, as we just had a 3 hour conversation trying to agree on what it does, with most people assuming it made the var global, as in, could be accessed in any scope.

Byond also has another var keyword, called static, it is identical to global, but it's not likely to get confused with a global var (as in, no scope/all scopes)

The static keyword is not documented, but i think it should be, and we should replace the global keyword with static, and depreciate the use of the global keyword.

(PS: reminder that there is also a global object, that acts like src, but for accessing global vars when you have name conflicts with a local var)
"static" is just global but without the ability to do global.variable. (IIRC)

the global keyword, and global.var are not connected in any way.

global is static, it's just a confusing name for the concept of a static class member property/field.

Hence this request, as everybody thinks the global modifier does things it doesn't.

It a static modifer, it behaves exactly like a static var does for classes in c++/c#/java/php.



Write up an article proposal and pop it in this thread, if you'd be so kind:
world.log << global:foo // prints "5"

var/global/foo = 5

This works. I'm not sure of the exact path it's using, but there must *be* a path somewhere.
Bumping this because ID:2175568 has made it clear the confusion with calling static vars global will never end.

depreciate global, replace with static.
Agreed with this. This confused the everloving crap out of me the first time I ran across it.
whole hearted +1
+1 from me too. global:foo *can* be used to access static/global members on datums, but it's better to do something like the following anyway.
var/static/foo = 2

var/datum/D = /datum // path, not instance

world.log << // 2 = 500
world.log << // 500