ID:2444319
 
Not a bug
BYOND Version:512
Operating System:Windows 10 Home
Web Browser:Chrome 73.0.3683.86
Applies to:Dream Maker
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
var string = "something"

var list/array_a = list(string = 444) // Compiles, is illogical. --> "string" = 444
var list/array_b = list("[string]" = 444) // Compiles, acts as intended. --> "something" = 444


Expected Results:
The ability to use variables as list indexes.

Actual Results:
The ability to use variables as list indexes, literally.

When does the problem NOT occur?
When you wrap the variable within a string as shown above.

Workarounds:
Fix it, this would be a nice feature :3
This is documented in the list association reference entry.
Lummox JR resolved issue (Not a bug)
You can work around this particular feature of the engine by doing the following :

var/x = "Your key"
var/list/L = list()
L[x] = "Your value"
In response to Shifty_rail
Shifty_rail wrote:
You can work around this particular feature of the engine by doing the following :

> var/x = "Your key"
> var/list/L = list()
> L[x] = "Your value"
>

What you've done is an associative list
This is what I thought of but with it being a feature.
Having to wrap it within a string is the only way that wouldn't require further code be added.

var _A = "attack"
var _B = "strength"

var list/_P = list(
_A = list(),
_B = list(),
)


var _A = "attack"
var _B = "strength"

var list/_P = list(
"[_A]" = list(),
"[_B]" = list(),
)
In response to Kozuma3
Kozuma3 wrote:
Shifty_rail wrote:
You can work around this particular feature of the engine by doing the following :

> > var/x = "Your key"
> > var/list/L = list()
> > L[x] = "Your value"
> >

What you've done is an associative list
This is what I thought of but with it being a feature.
Having to wrap it within a string is the only way that wouldn't require further code be added.

var _A = "attack"
> var _B = "strength"
>
> var list/_P = list(
> _A = list(),
> _B = list(),
> )


> var _A = "attack"
> var _B = "strength"
>
> var list/_P = list(
> "[_A]" = list(),
> "[_B]" = list(),
> )


they're both associative lists though, regardless of how you set your keys/indexes. This is a common thing in other languages - where you don't need to use the key as string; so it doesn't look for it to be a variable. It automatically uses any key as a string. It's odd but not unique to BYOND.
In response to Super Saiyan X
Super Saiyan X wrote:
It's odd but not unique to BYOND.

Very odd and illogical behavior that removes some freedom with the way you can/could utilize the syntax.

But, it's not of any real value to myself other than to structure lists more elegantly.
To be fair, this is a gotcha that is so universally thought of as a gotcha that one of these threads pops up every year.


"#define DISABLE_IMPLICIT_ASSOCIATIONS" When?
could steal from JS (which has the same problem) and allow like

var/A = "attack"
var/list/L = list([A] = "foo")
var/attack = L[A]