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.
this for instance functions just fine