ID:2381094
 
Resolved
Accessing a static var on a datum through its vars list, instead of by name, did not read the correct value.
BYOND Version:512.1431 and 512.1434
Operating System:Windows 10 Pro 64-bit
Web Browser:Chrome 64.0.3282.140
Applies to:Dream Daemon
Status: Resolved (512.1435)

This issue has been resolved.
Descriptive Problem Summary:

If you read a static var on a datum using .vars you'll only ever receive the initial value of it. We at /tg/ suspect this started in 1428 with the var init changes but have yet to confirm


Code Snippet (if applicable) to Reproduce Problem:
/datum
var/static/foo = 42

/world/New()
var/datum/D = new
for(var/I in D.vars)
log << "Var [I]: [D.vars[I]]"
D.foo = 89
for(var/I in D.vars)
log << "Var [I]: [D.vars[I]]"


Expected Results:

Welcome BYOND! (5.0 Beta Version 512.1434)
Var foo: 42
Var tag:
Var type: /datum
Var parent_type:
Var vars: /list
Var foo: 82
Var tag:
Var type: /datum
Var parent_type:
Var vars: /list


Actual Results:

Var foo: 42
Var tag:
Var type: /datum
Var parent_type:
Var vars: /list
Var foo: 42
Var tag:
Var type: /datum
Var parent_type:
Var vars: /list


Does the problem occur:
Every time

When does the problem NOT occur?

Never

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.)

Works in 1427

Workarounds:

This is the weird bit. If you do global.vars[varname] you get the true value, even though it's on /datum. Moreover having multiple static vars on different types with that name can lead to weirdness

See this test case.

/datum/golan
var/static/foo = 16

/datum/bar
var/static/foo = 42

/world/New()
var/datum/bar/D = new
for(var/I in D.vars)
log << "/bar Var [I]: [D.vars[I]]"
D.foo = 89
for(var/I in D.vars)
log << "updated /bar Var [I]: [D.vars[I]]"
for(var/I in global.vars)
log << "global Var [I]: [global.vars[I]]"

var/datum/golan/g = new
for(var/I in g.vars)
log << "/golan Var [I]: [g.vars[I]]"
del(src)


Results:

Logging in...
BYOND pager is offline. Connecting as Guest.
Tue Jul 03 14:24:34 2018
World opened on network port 53848.
Welcome BYOND! (5.0 Beta Version 512.1434)
/bar Var foo: 42
/bar Var tag:
/bar Var type: /datum/bar
/bar Var parent_type: /datum
/bar Var vars: /list
updated /bar Var foo: 42
updated /bar Var tag:
updated /bar Var type: /datum/bar
updated /bar Var parent_type: /datum
updated /bar Var vars: /list
global Var UNIX: UNIX
global Var NORTH: 1
global Var SOUTH: 2
global Var EAST: 4
global Var WEST: 8
global Var NORTHEAST: 5
global Var NORTHWEST: 9
global Var SOUTHEAST: 6
global Var SOUTHWEST: 10
global Var UP: 16
global Var DOWN: 32
global Var BLIND: 1
global Var SEE_MOBS: 4
global Var SEE_OBJS: 8
global Var SEE_TURFS: 16
global Var SEE_SELF: 32
global Var SEE_INFRA: 64
global Var SEE_PIXELS: 256
global Var SEE_THRU: 512
global Var SEE_BLACKNESS: 1024
global Var MOB_PERSPECTIVE: 0
global Var EYE_PERSPECTIVE: 1
global Var EDGE_PERSPECTIVE: 2
global Var FLOAT_LAYER: -1
global Var AREA_LAYER: 1
global Var TURF_LAYER: 2
global Var OBJ_LAYER: 3
global Var MOB_LAYER: 4
global Var FLY_LAYER: 5
global Var EFFECTS_LAYER: 5000
global Var TOPDOWN_LAYER: 10000
global Var BACKGROUND_LAYER: 20000
global Var FLOAT_PLANE: -32767
global Var TOPDOWN_MAP: 0
global Var ISOMETRIC_MAP: 1
global Var SIDE_MAP: 2
global Var TILED_ICON_MAP: 32768
global Var TRUE: 1
global Var FALSE: 0
global Var MALE: male
global Var FEMALE: female
global Var NEUTER: neuter
global Var PLURAL: plural
global Var MOUSE_INACTIVE_POINTER: 0
global Var MOUSE_ACTIVE_POINTER: 1
global Var MOUSE_DRAG_POINTER: 3
global Var MOUSE_DROP_POINTER: 4
global Var MOUSE_ARROW_POINTER: 5
global Var MOUSE_CROSSHAIRS_POINTER: 6
global Var MOUSE_HAND_POINTER: 7
global Var MOUSE_LEFT_BUTTON: 1
global Var MOUSE_RIGHT_BUTTON: 2
global Var MOUSE_MIDDLE_BUTTON: 4
global Var MOUSE_CTRL_KEY: 8
global Var MOUSE_SHIFT_KEY: 16
global Var MOUSE_ALT_KEY: 32
global Var MS_WINDOWS: MS Windows
global Var SOUND_MUTE: 1
global Var SOUND_PAUSED: 2
global Var SOUND_STREAM: 4
global Var SOUND_UPDATE: 16
global Var BLEND_DEFAULT: 0
global Var BLEND_OVERLAY: 1
global Var BLEND_ADD: 2
global Var BLEND_SUBTRACT: 3
global Var BLEND_MULTIPLY: 4
global Var foo: 89
global Var foo: 89
/golan Var foo: 16
/golan Var tag:
/golan Var type: /datum/golan
/golan Var parent_type: /datum
/golan Var vars: /list
Lummox JR resolved issue with message:
Accessing a static var on a datum through its vars list, instead of by name, did not read the correct value.
Good find. The new opt_var_defs list has been changed to never include static vars, and the var read/initial routines have been updated to reflect this change as well.

Interestingly, writing the var was not an issue.