ID:2828180
 
Not a bug
BYOND Version:514
Operating System:Windows 10 Enterprise 64-bit
Web Browser:Chrome 106.0.0.0
Applies to:DM Language
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:

I am testing out initialization for a new library - and newList suggests the curly praces { } intializations can be used anywhere


This is the most common use of "modified types", but it is not specific to the newlist instruction. Anywhere a type value may be used in DM, it may be followed by a list of initializations. The general syntax for a modified types is:

path {var1 = val1; var2 = val2}


The code below compiles fine, but I get a funky runtime

Code Snippet (if applicable) to Reproduce Problem:
/datum/myDatum
var/testVar = 10

/proc/main()
var/datum/myDatum/listDatum
var/list/listy = newlist(/datum/myDatum { testVar = 20 })
for(listDatum in listy)
world.log << listDatum.testVar

var/datum/myDatum/testDatum = /datum/myDatum {testVar = 30}
if(testDatum)
world.log << "testDatum exists"
world.log << testDatum.testVar


Expected Results:

I should be able to retrieve values from my object, as though I used new() and set the variable afterwards.

Actual Results:
Instead of the variable value, I get:
runtime error: Cannot read .testVar

Workarounds:

I can use newlist() and grab the object from the generated list, or I can use new() and set variables manually.
You aren't newing my datum
/datum/myDatum
var/testVar = 10

/proc/main()
var/datum/myDatum/testDatum = new /datum/myDatum {testVar = 30}
if(testDatum)
world.log << "testDatum exists"
world.log << testDatum.testVar

this for instance functions just fine
Lummox JR resolved issue (Not a bug)