global.vars
contains vars that are not in global scope, like proc and object-level static vars.This even applies to scoped vars with name collisions (which are allowed, and work fine); it will return the value of the last definition with that name, and modifying it will modify only that variable. However, the key will still be in the list twice (or three times, or more, depending on how many vars have that name).
Numbered Steps to Reproduce Problem:
1. Define a scoped static var using the
global
or static
keywords in a proc or on an object.2. Reference it outside of its proper scope with
global.vars["varname"]
. Observe that it compiles and gives the correct value of the var even though it is out of scope.3. Reference it using
global.varname
. Observe that it errors (as it should).Optional:
4. Create a scoped static var with the same name in a different, non-overlapping scope.
5. Try to access it again; global.vars["varname"] now refers to this var.
6. Iterate over global.vars and see that the key corresponding to that var shows up twice, but only has the value of the second definition.
Code Snippet (if applicable) to Reproduce Problem:
/obj/var/static/foo = "you shouldn't be able to access this"
/mob/var/static/foo = "you shouldn't be able to access this either"
/world/New()
var/obj/o = new
var/mob/m = new
world.log << "obj.foo: [o.foo]"
world.log << "mob.foo: [m.foo]"
for(var/i in 1 to length(global.vars))
var/glob = global.vars[i]
if (glob == "foo")
world.log << "global.vars\[[i]\]: \"[glob]\" = [global.vars[glob]]"
global.vars["foo"] = "but I can access it anyway"
world.log << "obj.foo: [o.foo]"
world.log << "mob.foo: [m.foo]"
Expected Results:
Code snippet should runtime with "Global var foo does not exist."
Actual Results:
DM allows access to a scoped static var outside its scope, which causes strange results when those vars have names that conflict. Vars that have colliding names show up in
global.vars
multiple times, but each entry only has the value of the last definition, and allows modifying the last instance of that variable.Does the problem occur:
Every time? Or how often?
Whenever you do this.
In other games?
If they do this, sure.
In other user accounts?
Yes.
On other computers?
Yes.
When does the problem NOT occur?
With non-static scoped variables.
Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
I believe it has occurred since global.vars was introduced, which I think is BYOND 512?
Workarounds:
Don't access the vars this way, or don't use scoped static vars.